tito 0.1.11 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env +2 -0
- data/lib/tito.rb +14 -6
- data/lib/tito/account.rb +6 -6
- data/lib/tito/answer.rb +3 -3
- data/lib/tito/base.rb +147 -4
- data/lib/tito/event.rb +53 -28
- data/lib/tito/eventable.rb +41 -26
- data/lib/tito/request_proxy.rb +21 -0
- data/lib/tito/response_array.rb +3 -0
- data/lib/tito/ticket.rb +14 -12
- data/lib/tito/version.rb +1 -1
- data/lib/tito/webhook_endpoint.rb +1 -1
- data/tito.gemspec +6 -1
- metadata +77 -5
- data/lib/tito/oauth2_middleware.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9de5568949fb5d26465e2eee09d1d3cd97bb7fea
|
4
|
+
data.tar.gz: 5bd9c944468cb8d59c92657c2150c520571234d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19e2e93e3ed7238d288c7a84800d2091d3134022177bb80418ce3d233f99482feaf761d493d97ebd994e34c8ffcf8e46f15016fc4b74bb6fbcdb028fc3d177e7
|
7
|
+
data.tar.gz: 1ad72e81a785d828c67594e1be8abd493c96412376e12e25d7a0dd121ac0bb343f51a2b17416343021143a3543d779297ec6e5365a63952eee51a7e827e250ab
|
data/.env
ADDED
data/lib/tito.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
require '
|
1
|
+
require 'http'
|
2
2
|
require "tito/version"
|
3
3
|
require "tito/base"
|
4
|
-
require "tito/oauth2_middleware"
|
5
4
|
require "tito/eventable"
|
5
|
+
require "tito/request_proxy"
|
6
|
+
require "tito/response_array"
|
6
7
|
|
7
8
|
require "tito/account"
|
8
9
|
require "tito/answer"
|
@@ -17,9 +18,16 @@ require "tito/event"
|
|
17
18
|
require "tito/webhook_endpoint"
|
18
19
|
|
19
20
|
module Tito
|
20
|
-
|
21
|
+
def self.api_key
|
22
|
+
return @api_key if @api_key
|
23
|
+
return ENV['TITO_API_KEY'] if ENV['TITO_API_KEY']
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.api_key=(val)
|
27
|
+
@api_key = val
|
28
|
+
end
|
21
29
|
end
|
22
30
|
|
23
|
-
Tito::Base.connection do |connection|
|
24
|
-
|
25
|
-
end
|
31
|
+
# Tito::Base.connection do |connection|
|
32
|
+
# connection.use Tito::OAuth2Middleware, lambda { |env| Tito.api_key }
|
33
|
+
# end
|
data/lib/tito/account.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Tito
|
2
2
|
class Account < Base
|
3
|
-
property :name, type: :string
|
4
|
-
property :description, type: :string
|
5
|
-
property :slug, type: :string
|
3
|
+
# property :name, type: :string
|
4
|
+
# property :description, type: :string
|
5
|
+
# property :slug, type: :string
|
6
6
|
|
7
|
-
def events
|
8
|
-
|
9
|
-
end
|
7
|
+
# def events
|
8
|
+
# Tito::Event.where(account_id: id)
|
9
|
+
# end
|
10
10
|
end
|
11
11
|
end
|
data/lib/tito/answer.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Tito
|
2
2
|
class Answer < Base
|
3
|
-
property :response, type: :string
|
4
|
-
property :question_slug, type: :string
|
5
|
-
property :question_title, type: :string
|
3
|
+
# property :response, type: :string
|
4
|
+
# property :question_slug, type: :string
|
5
|
+
# property :question_title, type: :string
|
6
6
|
end
|
7
7
|
end
|
data/lib/tito/base.rb
CHANGED
@@ -1,11 +1,154 @@
|
|
1
1
|
module Tito
|
2
|
-
class Base
|
2
|
+
class Base
|
3
|
+
attr_accessor :path_prefix
|
3
4
|
def self.site
|
4
|
-
ENV['TITO_SITE'] || "https://api.tito.io/v2"
|
5
|
+
@site || ENV['TITO_SITE'] || "https://api.tito.io/v2"
|
5
6
|
end
|
6
7
|
|
7
|
-
def self.
|
8
|
-
|
8
|
+
def self.site=(val)
|
9
|
+
@site = val
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.auth(api_key: nil)
|
13
|
+
token = api_key || Tito.api_key
|
14
|
+
raise "API key is required" if !token
|
15
|
+
if token.length > 30
|
16
|
+
%(Bearer #{token})
|
17
|
+
else
|
18
|
+
%(Token token="#{token}")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.ssl_context
|
23
|
+
@ssl_context ||= begin
|
24
|
+
ctx = OpenSSL::SSL::SSLContext.new
|
25
|
+
ctx
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.ssl_context=(ctx)
|
30
|
+
@ssl_context = ctx
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.http(api_key: nil)
|
34
|
+
HTTP.auth(auth(api_key: nil)).accept("application/json")
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.resource_path=(val)
|
38
|
+
@resource_path = val
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.resource_name=(val)
|
42
|
+
@resource_name = val
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.underscore_class_name
|
46
|
+
self.to_s.gsub(/::/, '/').
|
47
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
48
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
49
|
+
tr("-", "_").
|
50
|
+
downcase
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.resource_name
|
54
|
+
@resource_name ||= underscore_class_name.split("/").last
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.resource_path
|
58
|
+
@resource_path ||= "#{resource_name}s"
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.get_url(path)
|
62
|
+
[Tito::Base.site, path].join("/")
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.get(path, params = {})
|
66
|
+
new http.get(get_url(path), params: params, ssl_context: ssl_context).parse[resource_name]
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.all_path(path_prefix: nil)
|
70
|
+
[path_prefix, resource_path].compact.join("/")
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.all_url(path_prefix: nil)
|
74
|
+
[site, all_path(path_prefix: path_prefix)].join("/")
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.all(params = {})
|
78
|
+
api_key = params.delete(:api_key)
|
79
|
+
path_prefix = params.delete(:path_prefix)
|
80
|
+
response = http(api_key: api_key).get(all_url(path_prefix: path_prefix), params: params, ssl_context: ssl_context).parse
|
81
|
+
all_records = response[self.resource_path]
|
82
|
+
meta = response["meta"]
|
83
|
+
out = ResponseArray.new(all_records.collect do |record|
|
84
|
+
new record
|
85
|
+
end)
|
86
|
+
out.meta = meta
|
87
|
+
out
|
88
|
+
end
|
89
|
+
|
90
|
+
def initialize(attrs = {})
|
91
|
+
self.path_prefix = (attrs ||= {}).delete(:path_prefix)
|
92
|
+
attrs.each do |key, val|
|
93
|
+
attributes[key.to_s] = val
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def attributes
|
98
|
+
@attributes ||= {}
|
99
|
+
end
|
100
|
+
|
101
|
+
def attributes=(attrs)
|
102
|
+
@attributes = attrs
|
103
|
+
end
|
104
|
+
|
105
|
+
def method_missing(method_name, val = nil)
|
106
|
+
if method_name.to_s[-1] == "="
|
107
|
+
self.attributes[method_name[0, (method_name.length - 1)]] = val
|
108
|
+
else
|
109
|
+
self.attributes[method_name.to_s]
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def new_record?
|
114
|
+
attributes["id"] == nil
|
115
|
+
end
|
116
|
+
|
117
|
+
def persisted?
|
118
|
+
!new_record?
|
119
|
+
end
|
120
|
+
|
121
|
+
def auth(api_key = nil)
|
122
|
+
self.class.auth(api_key: api_key)
|
123
|
+
end
|
124
|
+
|
125
|
+
def http(api_key = nil)
|
126
|
+
self.class.http(api_key: api_key)
|
127
|
+
end
|
128
|
+
|
129
|
+
def ssl_context
|
130
|
+
self.class.ssl_context
|
131
|
+
end
|
132
|
+
|
133
|
+
def put_url
|
134
|
+
[Tito::Base.site, put_path].join("/")
|
135
|
+
end
|
136
|
+
|
137
|
+
def post_url
|
138
|
+
[Tito::Base.site, post_path].join("/")
|
139
|
+
end
|
140
|
+
|
141
|
+
def save(api_key: nil)
|
142
|
+
if persisted?
|
143
|
+
attrs = http(api_key: api_key).put(put_url, json: {self.class.resource_name => attributes}, ssl_context: ssl_context).parse[self.class.resource_name]
|
144
|
+
else
|
145
|
+
attrs = http(api_key: api_key).post(post_url, json: {self.class.resource_name => attributes}, ssl_context: ssl_context).parse[self.class.resource_name]
|
146
|
+
end
|
147
|
+
self.attributes = attrs
|
148
|
+
end
|
149
|
+
|
150
|
+
def destroy(api_key: nil)
|
151
|
+
http(api_key: api_key).delete(put_url, ssl_context: ssl_context)
|
9
152
|
end
|
10
153
|
end
|
11
154
|
end
|
data/lib/tito/event.rb
CHANGED
@@ -1,40 +1,65 @@
|
|
1
1
|
module Tito
|
2
|
-
class Event < Base
|
3
|
-
belongs_to :account
|
2
|
+
class Event < Base
|
4
3
|
|
5
|
-
|
6
|
-
|
4
|
+
def path
|
5
|
+
"#{account_slug}/#{slug}"
|
6
|
+
end
|
7
7
|
|
8
|
-
def
|
9
|
-
|
8
|
+
def put_path
|
9
|
+
path
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
|
12
|
+
def post_path
|
13
|
+
"#{account_slug}/events"
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
|
16
|
+
def self.for_account(url)
|
17
|
+
RequestProxy.new(proxy_class: self, proxy_path: url)
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
def get(path)
|
23
|
-
parts = path.split('/')
|
24
|
-
where(account_id: parts[0]).find(parts[1]).first
|
25
|
-
end
|
26
|
-
|
27
|
-
def path(params=nil)
|
28
|
-
prefix_path = '%{account_id}'
|
29
|
-
path_params = params.delete(:path) || params
|
30
|
-
parts = [].unshift(prefix_path % path_params.symbolize_keys)
|
31
|
-
if !params[:id]
|
32
|
-
parts << 'events'
|
33
|
-
end
|
34
|
-
File.join(*parts)
|
35
|
-
rescue KeyError
|
36
|
-
raise ArgumentError, "Please make sure to include account_id"
|
37
|
-
end
|
20
|
+
def self.[](url)
|
21
|
+
self.for_account(url)
|
38
22
|
end
|
23
|
+
|
24
|
+
# property :title, type: :string
|
25
|
+
# property :slug, type: :string
|
26
|
+
# property :account_slug, type: :string
|
27
|
+
# property :security_token, type: :string
|
28
|
+
|
29
|
+
# def account_id
|
30
|
+
# attributes['account_id'] || attributes['account-id']
|
31
|
+
# end
|
32
|
+
|
33
|
+
# def account_id=(val)
|
34
|
+
# attributes['account_id'] = val
|
35
|
+
# end
|
36
|
+
|
37
|
+
# def security_token
|
38
|
+
# attributes['security_token'] || attributes['security-token']
|
39
|
+
# end
|
40
|
+
|
41
|
+
# def account_slug
|
42
|
+
# attributes['account_slug'] || attributes['account-slug']
|
43
|
+
# end
|
44
|
+
|
45
|
+
# class << self
|
46
|
+
|
47
|
+
# def get(path)
|
48
|
+
# parts = path.split('/')
|
49
|
+
# where(account_id: parts[0]).find(parts[1]).first
|
50
|
+
# end
|
51
|
+
|
52
|
+
# def path(params=nil)
|
53
|
+
# prefix_path = '%{account_id}'
|
54
|
+
# path_params = params.delete(:path) || params
|
55
|
+
# parts = [].unshift(prefix_path % path_params.symbolize_keys)
|
56
|
+
# if !params[:id]
|
57
|
+
# parts << 'events'
|
58
|
+
# end
|
59
|
+
# File.join(*parts)
|
60
|
+
# rescue KeyError
|
61
|
+
# raise ArgumentError, "Please make sure to include account_id"
|
62
|
+
# end
|
63
|
+
# end
|
39
64
|
end
|
40
65
|
end
|
data/lib/tito/eventable.rb
CHANGED
@@ -4,42 +4,57 @@ module Tito
|
|
4
4
|
def self.included(base)
|
5
5
|
base.extend ClassMethods
|
6
6
|
base.class_eval do
|
7
|
-
|
8
|
-
|
7
|
+
attr_accessor :event_slug
|
8
|
+
attr_accessor :account_slug
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
self.
|
14
|
-
self.attributes[:event] = tito_event
|
15
|
-
@event = tito_event
|
12
|
+
def put_path
|
13
|
+
[path_prefix, self.class.resource_path, id].join("/")
|
16
14
|
end
|
17
15
|
|
18
|
-
|
16
|
+
def post_path
|
17
|
+
[path_prefix, self.class.resource_path].join("/")
|
18
|
+
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
# def event=(tito_event)
|
21
|
+
# self.event_id = tito_event.id
|
22
|
+
# self.attributes[:event] = tito_event
|
23
|
+
# @event = tito_event
|
24
|
+
# end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
module ClassMethods
|
27
|
+
def for_event(url)
|
28
|
+
RequestProxy.new(proxy_class: self, proxy_path: url)
|
28
29
|
end
|
29
30
|
|
30
|
-
def
|
31
|
-
|
32
|
-
path_params = params.delete(:path) || params
|
33
|
-
path_params[:event_id] = event_id_from_params(params)
|
34
|
-
path_params[:account_id] = account_id_from_params(params)
|
35
|
-
parts = [].unshift(prefix_path % path_params.symbolize_keys)
|
36
|
-
parts << table_name
|
37
|
-
|
38
|
-
File.join(*parts)
|
39
|
-
|
40
|
-
rescue KeyError
|
41
|
-
raise ArgumentError, "Please make sure to include account_id and event_id"
|
31
|
+
def [](url)
|
32
|
+
self.for_event(url)
|
42
33
|
end
|
34
|
+
|
35
|
+
# def event_id_from_params(params)
|
36
|
+
# return params[:event][:slug] if params[:event]
|
37
|
+
# return params[:filter][:event_id] if params[:filter]
|
38
|
+
# end
|
39
|
+
|
40
|
+
# def account_id_from_params(params)
|
41
|
+
# return params[:event]["account-slug"] if params[:event]
|
42
|
+
# return params[:filter][:account_id] if params[:filter]
|
43
|
+
# end
|
44
|
+
|
45
|
+
# def path(params=nil)
|
46
|
+
# prefix_path = '%{account_id}/%{event_id}'
|
47
|
+
# path_params = params.delete(:path) || params
|
48
|
+
# path_params[:event_id] = event_id_from_params(params)
|
49
|
+
# path_params[:account_id] = account_id_from_params(params)
|
50
|
+
# parts = [].unshift(prefix_path % path_params.symbolize_keys)
|
51
|
+
# parts << table_name
|
52
|
+
|
53
|
+
# File.join(*parts)
|
54
|
+
|
55
|
+
# rescue KeyError
|
56
|
+
# raise ArgumentError, "Please make sure to include account_id and event_id"
|
57
|
+
# end
|
43
58
|
end
|
44
59
|
end
|
45
60
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Tito
|
2
|
+
class RequestProxy
|
3
|
+
attr_accessor :proxy_path
|
4
|
+
attr_accessor :proxy_class
|
5
|
+
attr_accessor :api_key
|
6
|
+
|
7
|
+
def initialize(proxy_class: nil, proxy_path: nil, api_key: nil)
|
8
|
+
@proxy_path = proxy_path
|
9
|
+
@proxy_class = proxy_class
|
10
|
+
@api_key = api_key
|
11
|
+
end
|
12
|
+
|
13
|
+
def all
|
14
|
+
proxy_class.all(path_prefix: proxy_path, api_key: api_key)
|
15
|
+
end
|
16
|
+
|
17
|
+
def new(attrs = {})
|
18
|
+
proxy_class.new(attrs.merge(path_prefix: proxy_path, api_key: api_key))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/tito/ticket.rb
CHANGED
@@ -2,20 +2,22 @@ module Tito
|
|
2
2
|
class Ticket < Tito::Base
|
3
3
|
include Eventable
|
4
4
|
|
5
|
-
property :url, type: :string
|
6
|
-
property :name, type: :string
|
7
|
-
property :email, type: :string
|
5
|
+
# property :url, type: :string
|
6
|
+
# property :name, type: :string
|
7
|
+
# property :email, type: :string
|
8
8
|
|
9
|
-
property :company_name, type: :string
|
9
|
+
# property :company_name, type: :string
|
10
10
|
|
11
|
-
property :metadata, type: :string
|
11
|
+
# property :metadata, type: :string
|
12
12
|
|
13
|
-
property :number, type: :integer
|
14
|
-
property :phone_number, type: :string
|
15
|
-
property :price, type: :string
|
16
|
-
property :reference, type: :string
|
17
|
-
property :state, type: :string
|
18
|
-
property :tags, type: :string
|
19
|
-
property :test_mode, type: :boolean
|
13
|
+
# property :number, type: :integer
|
14
|
+
# property :phone_number, type: :string
|
15
|
+
# property :price, type: :string
|
16
|
+
# property :reference, type: :string
|
17
|
+
# property :state, type: :string
|
18
|
+
# property :tags, type: :string
|
19
|
+
# property :test_mode, type: :boolean
|
20
|
+
|
21
|
+
# property :registration
|
20
22
|
end
|
21
23
|
end
|
data/lib/tito/version.rb
CHANGED
data/tito.gemspec
CHANGED
@@ -19,8 +19,13 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_runtime_dependency '
|
22
|
+
spec.add_runtime_dependency 'http', '<3'
|
23
|
+
spec.add_runtime_dependency 'virtus', '<2'
|
23
24
|
|
24
25
|
spec.add_development_dependency "bundler", "~> 1.10"
|
25
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "minitest", "~> 5.10"
|
28
|
+
spec.add_development_dependency "dotenv", "~> 2.2"
|
29
|
+
spec.add_development_dependency "byebug", "~> 9.0"
|
30
|
+
spec.add_development_dependency "webmock", "~> 2.3"
|
26
31
|
end
|
metadata
CHANGED
@@ -1,17 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tito
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Campbell
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: http
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "<"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "<"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: virtus
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
31
|
- - "<"
|
@@ -52,6 +66,62 @@ dependencies:
|
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.10'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.10'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: dotenv
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.2'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.2'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: byebug
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '9.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '9.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: webmock
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '2.3'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '2.3'
|
55
125
|
description: Allows interaction with the Tito API
|
56
126
|
email:
|
57
127
|
- paul@rslw.com
|
@@ -59,6 +129,7 @@ executables: []
|
|
59
129
|
extensions: []
|
60
130
|
extra_rdoc_files: []
|
61
131
|
files:
|
132
|
+
- ".env"
|
62
133
|
- ".gitignore"
|
63
134
|
- ".travis.yml"
|
64
135
|
- CODE_OF_CONDUCT.md
|
@@ -77,10 +148,11 @@ files:
|
|
77
148
|
- lib/tito/event_settings.rb
|
78
149
|
- lib/tito/eventable.rb
|
79
150
|
- lib/tito/interested_user.rb
|
80
|
-
- lib/tito/oauth2_middleware.rb
|
81
151
|
- lib/tito/question.rb
|
82
152
|
- lib/tito/registration.rb
|
83
153
|
- lib/tito/release.rb
|
154
|
+
- lib/tito/request_proxy.rb
|
155
|
+
- lib/tito/response_array.rb
|
84
156
|
- lib/tito/ticket.rb
|
85
157
|
- lib/tito/version.rb
|
86
158
|
- lib/tito/webhook_endpoint.rb
|
@@ -106,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
178
|
version: '0'
|
107
179
|
requirements: []
|
108
180
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.5.
|
181
|
+
rubygems_version: 2.5.2
|
110
182
|
signing_key:
|
111
183
|
specification_version: 4
|
112
184
|
summary: Consumer library for Tito API
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module Tito
|
2
|
-
class OAuth2Middleware < FaradayMiddleware::OAuth2
|
3
|
-
def call(env)
|
4
|
-
params = query_params(env[:url])
|
5
|
-
|
6
|
-
token = params.delete(:api_key) || params.delete('api_key')
|
7
|
-
token ||= if @token.is_a?(Proc)
|
8
|
-
@token.call(env)
|
9
|
-
else
|
10
|
-
@token
|
11
|
-
end
|
12
|
-
|
13
|
-
token ||= Tito.api_key
|
14
|
-
|
15
|
-
if token.respond_to?(:empty?) && !token.empty?
|
16
|
-
env[:url].query = build_query params
|
17
|
-
if token.length > 30
|
18
|
-
env[:request_headers][AUTH_HEADER] ||= %(Bearer #{token})
|
19
|
-
else
|
20
|
-
env[:request_headers][AUTH_HEADER] ||= %(Token token="#{token}")
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
@app.call env
|
25
|
-
end
|
26
|
-
|
27
|
-
def initialize(app, token = nil, options = {})
|
28
|
-
super(app)
|
29
|
-
options, token = token, nil if token.is_a? Hash
|
30
|
-
@token = token
|
31
|
-
raise ArgumentError, ":param_name can't be blank" if @param_name.empty?
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|