diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..7f12228 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +# Specify your gem's dependencies in jpl-gem.gemspec +gemspec diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..82ff3d9 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,39 @@ +PATH + remote: . + specs: + sirportly (2.0.0) + multipart-post (~> 2.0.0) + +GEM + remote: https://rubygems.org/ + specs: + builder (3.2.2) + faraday (0.9.0) + multipart-post (>= 1.2, < 3) + geminabox (0.12.4) + builder + faraday + httpclient (>= 2.2.7) + nesty + sinatra (>= 1.2.7) + httpclient (2.5.2) + multipart-post (2.0.0) + nesty (1.0.2) + rack (1.5.2) + rack-protection (1.5.3) + rack + rake (10.3.2) + sinatra (1.4.5) + rack (~> 1.4) + rack-protection (~> 1.4) + tilt (~> 1.3, >= 1.3.4) + tilt (1.4.1) + +PLATFORMS + ruby + +DEPENDENCIES + bundler (>= 1.3.0) + geminabox + rake + sirportly! diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..ac19e62 --- /dev/null +++ b/Rakefile @@ -0,0 +1,13 @@ +require "bundler/gem_tasks" + +# Don't push the gem to rubygems +ENV["gem_push"] = "false" # Utilizes feature in bundler 1.3.0 + +# Let bundler's release task do its job, minus the push to Rubygems, +# and after it completes, use "gem inabox" to publish the gem to our +# internal gem server. + +Rake::Task["release"].enhance do + spec = Gem::Specification::load(Dir.glob("*.gemspec").first) + sh "gem inabox pkg/#{spec.name}-#{spec.version}.gem" +end diff --git a/lib/sirportly.rb b/lib/sirportly.rb index 3d7991a..128c4a6 100644 --- a/lib/sirportly.rb +++ b/lib/sirportly.rb @@ -3,10 +3,9 @@ require 'net/https' require 'json' -require 'net/http/post/multipart' - require 'sirportly/client' require 'sirportly/request' +require 'sirportly/request_v2' require 'sirportly/data_set' require 'sirportly/data_object' require 'sirportly/spql_query' @@ -29,9 +28,10 @@ require 'sirportly/data_objects/ticket' require 'sirportly/data_objects/ticket_update' require 'sirportly/data_objects/user' +require 'sirportly/data_objects/support_centre' module Sirportly - VERSION = '1.3.8' + VERSION = '2.0.0' class << self diff --git a/lib/sirportly/client.rb b/lib/sirportly/client.rb index 59aa56b..c96bab5 100644 --- a/lib/sirportly/client.rb +++ b/lib/sirportly/client.rb @@ -7,10 +7,15 @@ def initialize(token, secret) @token, @secret = token, secret end - ## Make a request using this client's authentication token and return the request. + ## Make a v1 api request using this client's authentication token and return the request. def request(*args) Request.request(self, *args) end + + ## Make a v1 api request using this client's authentication token and return the request. + def request_v2(*args) + RequestV2.request(self, *args) + end ## Return all brands def brands @@ -116,6 +121,10 @@ def user(q) def create_user(params = {}) User.create(self, params) end + + def support_centres(opts = {}) + SupportCentre.all(self, opts) + end ## Return all api token def api_tokens diff --git a/lib/sirportly/data_objects/support_centre.rb b/lib/sirportly/data_objects/support_centre.rb new file mode 100644 index 0000000..a41f91e --- /dev/null +++ b/lib/sirportly/data_objects/support_centre.rb @@ -0,0 +1,22 @@ +module Sirportly + class SupportCentre < DataObject + self.collection_path = 'support_centres/list' + + ## request an auth token for support centre, allowing to authenticate a user + def auth_token(opts = {}) + if req = client.request_v2('authentication/support_centre_token', opts.merge(:support_centre => self.id)) + req + else + false + end + end + + def redirect_uri(support_centre_token, return_to = nil) + support_centre_token = if support_centre_token.is_a?(Hash) + support_centre_token['token'] + end + + URI::HTTP.build([nil, self.access_domain, nil, ['/login', support_centre_token].join('/'), return_to ? "return_to=#{return_to}" : nil, nil]).to_s + end + end +end diff --git a/lib/sirportly/request.rb b/lib/sirportly/request.rb index faadc2b..cb382bf 100644 --- a/lib/sirportly/request.rb +++ b/lib/sirportly/request.rb @@ -23,9 +23,13 @@ def success? def output @output || nil end - + + def api_version + @api_version ||= 'api/v1' + end + def make - uri = URI.parse([Sirportly.domain, "api/v1", @path].join('/')) + uri = URI.parse([Sirportly.domain, self.api_version, @path].join('/')) http_request = http_req(uri, @data.stringify_keys) http_request.add_field("User-Agent", "SirportlyRubyClient/#{Sirportly::VERSION}") http_request.add_field("X-Auth-Token", @client.token) @@ -102,4 +106,4 @@ def http_req(uri, data) end end -end \ No newline at end of file +end diff --git a/lib/sirportly/request_v2.rb b/lib/sirportly/request_v2.rb new file mode 100644 index 0000000..e8d9736 --- /dev/null +++ b/lib/sirportly/request_v2.rb @@ -0,0 +1,14 @@ +module Sirportly + class RequestV2 < Request + + def self.request(client, path, data = {}) + req = self.new(client, path, :post) + req.data = data + req.make && req.success? ? req.output : false + end + + def api_version + @api_version ||= 'api/v2' + end + end +end diff --git a/sirportly.gemspec b/sirportly.gemspec index d3dad5c..183e4e5 100644 --- a/sirportly.gemspec +++ b/sirportly.gemspec @@ -10,9 +10,14 @@ Gem::Specification.new do |s| s.files = Dir["lib/sirportly.rb", 'lib/sirportly/**/*.rb'] s.bindir = "bin" s.require_path = 'lib' - s.add_dependency('multipart-post', '~> 1.2.0') + s.add_dependency('multipart-post', '~> 2.0.0') s.has_rdoc = false s.author = "Adam Cooke" s.email = "adam@atechmedia.com" s.homepage = "http://www.sirportly.com" + + s.add_development_dependency "rake" + s.add_development_dependency "bundler", ">= 1.3.0" + s.add_development_dependency "geminabox" + end