Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support centre api #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in jpl-gem.gemspec
gemspec
39 changes: 39 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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!
13 changes: 13 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions lib/sirportly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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

Expand Down
11 changes: 10 additions & 1 deletion lib/sirportly/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions lib/sirportly/data_objects/support_centre.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 7 additions & 3 deletions lib/sirportly/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -102,4 +106,4 @@ def http_req(uri, data)
end

end
end
end
14 changes: 14 additions & 0 deletions lib/sirportly/request_v2.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion sirportly.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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