supportbee 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ require_relative 'supportbee/client.rb'
2
+ require 'json/ext'
3
+ require 'openssl'
4
+ require 'faraday'
5
+ require 'json'
6
+
7
+ OpenSSL::SSL.send :remove_const, :VERIFY_PEER
8
+ OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
@@ -0,0 +1,53 @@
1
+ require_relative 'client/tickets.rb'
2
+ require_relative 'client/agents.rb'
3
+ require_relative 'client/groups.rb'
4
+ require 'json'
5
+
6
+ module Supportbee
7
+ class Client
8
+
9
+ include Supportbee::Client::Tickets
10
+ include Supportbee::Client::Agents
11
+ include Supportbee::Client::Groups
12
+
13
+ def initialize(options={})
14
+ @company = options[:company]
15
+ @host = "https://#{@company}.supportbee.com"
16
+ @auth_token = options[:auth_token]
17
+ @conn = Faraday.new(:url => @host) do |faraday|
18
+ faraday.params[:auth_token] = @auth_token
19
+ faraday.request :url_encoded # form-encode POST params
20
+ faraday.response :logger # log requests to STDOUT
21
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
22
+ end
23
+ end
24
+
25
+ def request(url, options = {})
26
+ method = options[:method].nil? ? :get : options[:method]
27
+ response = @conn.run_request(method, url, options[:body], options[:headers])
28
+ JSON.parse(response.body)
29
+ end
30
+
31
+ def index(model, extra_parameters = {})
32
+ items = []
33
+ current_page = 1
34
+ last_page = false
35
+ until last_page
36
+ extra_parameters['page'] = current_page
37
+ raw_response = @conn.get do |req|
38
+ req.url "/#{model}.json"
39
+ req.params.merge!(extra_parameters)
40
+ end
41
+ response = JSON.parse(raw_response.body)
42
+ items.concat(response[model])
43
+ if response['current_page'].to_i >= response['total_pages'].to_i
44
+ last_page = true
45
+ else
46
+ current_page = current_page + 1
47
+ end
48
+ end
49
+ items
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,15 @@
1
+ module Supportbee
2
+ class Client
3
+ module Agents
4
+
5
+ def agents(extra_parameters = {})
6
+ index('users', extra_parameters)
7
+ end
8
+
9
+ def agent(id)
10
+ response = @conn.get "/users/#{id}.json"
11
+ JSON.parse(response.body)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module Supportbee
2
+ class Client
3
+ module Groups
4
+
5
+ def groups(extra_parameters = {})
6
+ index('groups', extra_parameters)
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Supportbee
2
+ class Client
3
+ module Labels
4
+
5
+ def labels(extra_parameters = {})
6
+ index('labels', extra_parameters)
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Supportbee
2
+ class Client
3
+ module Snippets
4
+
5
+ def snippets(extra_parameters = {})
6
+ index('snippets', extra_parameters)
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,36 @@
1
+ module Supportbee
2
+ class Client
3
+ module Tickets
4
+
5
+ def tickets(extra_parameters = {})
6
+ # Default parameters according to
7
+ # https://developers.supportbee.com/api
8
+ if extra_parameters['archived'].nil?
9
+ extra_parameters['archived'] = false
10
+ end
11
+ if extra_parameters['spam'].nil?
12
+ extra_parameters['spam'] = false
13
+ end
14
+ if extra_parameters['trash'].nil?
15
+ extra_parameters['trash'] = false
16
+ end
17
+ tickets = index('tickets', extra_parameters)
18
+ # Dirty trick to avoid getting wrong tickets in case the API doesn't
19
+ # honor some parameters
20
+ known_filters = ['spam', 'trash', 'archived']
21
+ filters = extra_parameters.select do |p|
22
+ known_filters.include?(p)
23
+ end
24
+ tickets.select do |t|
25
+ !filters.map {|k,v| t[k].to_s == v.to_s}.include?(false)
26
+ end
27
+ end
28
+
29
+ def ticket(id)
30
+ response = @conn.get "/tickets/#{id}.json"
31
+ JSON.parse(response.body)
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,11 @@
1
+ module Supportbee
2
+ class Client
3
+ module WebHooks
4
+
5
+ def web_hooks(extra_parameters = {})
6
+ index('web_hooks', extra_parameters)
7
+ end
8
+
9
+ end
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: supportbee
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Luis Bosque
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.1.0
30
+ description: Ruby client for Supportbee API
31
+ email: luisico@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - lib/supportbee.rb
37
+ - lib/supportbee/client.rb
38
+ - lib/supportbee/client/snippets.rb
39
+ - lib/supportbee/client/tickets.rb
40
+ - lib/supportbee/client/labels.rb
41
+ - lib/supportbee/client/groups.rb
42
+ - lib/supportbee/client/web_hooks.rb
43
+ - lib/supportbee/client/agents.rb
44
+ homepage: https://github.com/lbosque/supportbee
45
+ licenses:
46
+ - MIT
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.23
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Ruby client for Supportbee API
69
+ test_files: []