From a78fbddf4e626eeea124624a0f5a22946c26023a Mon Sep 17 00:00:00 2001 From: jpl Date: Thu, 19 Dec 2013 12:11:10 +0100 Subject: [PATCH 1/3] Added support centre api --- Gemfile | 4 ++++ Gemfile.lock | 16 ++++++++++++++ lib/sirportly.rb | 2 ++ lib/sirportly/client.rb | 11 +++++++++- lib/sirportly/data_objects/support_centre.rb | 22 ++++++++++++++++++++ lib/sirportly/request.rb | 10 ++++++--- lib/sirportly/request_v2.rb | 14 +++++++++++++ 7 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 lib/sirportly/data_objects/support_centre.rb create mode 100644 lib/sirportly/request_v2.rb 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..0444e88 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,16 @@ +PATH + remote: . + specs: + sirportly (1.3.3) + multipart-post (= 1.2.0) + +GEM + remote: https://rubygems.org/ + specs: + multipart-post (1.2.0) + +PLATFORMS + ruby + +DEPENDENCIES + sirportly! diff --git a/lib/sirportly.rb b/lib/sirportly.rb index 3d7991a..9f98cb5 100644 --- a/lib/sirportly.rb +++ b/lib/sirportly.rb @@ -7,6 +7,7 @@ require 'sirportly/client' require 'sirportly/request' +require 'sirportly/request_v2' require 'sirportly/data_set' require 'sirportly/data_object' require 'sirportly/spql_query' @@ -29,6 +30,7 @@ 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' 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 From b1980f341f196bbb865cb12aef8f0f687a1c1483 Mon Sep 17 00:00:00 2001 From: adrien Date: Thu, 30 Oct 2014 12:21:48 +0100 Subject: [PATCH 2/3] Use private gem server --- Gemfile.lock | 29 ++++++++++++++++++++++++++--- Rakefile | 13 +++++++++++++ lib/sirportly.rb | 2 +- sirportly.gemspec | 7 ++++++- 4 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 Rakefile diff --git a/Gemfile.lock b/Gemfile.lock index 0444e88..82ff3d9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,16 +1,39 @@ PATH remote: . specs: - sirportly (1.3.3) - multipart-post (= 1.2.0) + sirportly (2.0.0) + multipart-post (~> 2.0.0) GEM remote: https://rubygems.org/ specs: - multipart-post (1.2.0) + 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 9f98cb5..2504aaa 100644 --- a/lib/sirportly.rb +++ b/lib/sirportly.rb @@ -33,7 +33,7 @@ require 'sirportly/data_objects/support_centre' module Sirportly - VERSION = '1.3.8' + VERSION = '2.0.0' class << self 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 From ebe5ec1fd3ec127e18055a361de0d13b804115f7 Mon Sep 17 00:00:00 2001 From: jpl Date: Tue, 29 Aug 2017 23:28:18 +0200 Subject: [PATCH 3/3] Update sirportly.rb Fix --- lib/sirportly.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/sirportly.rb b/lib/sirportly.rb index 2504aaa..128c4a6 100644 --- a/lib/sirportly.rb +++ b/lib/sirportly.rb @@ -3,8 +3,6 @@ require 'net/https' require 'json' -require 'net/http/post/multipart' - require 'sirportly/client' require 'sirportly/request' require 'sirportly/request_v2'