ticketinghub 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ticketing_hub/client.rb +28 -37
- data/lib/ticketing_hub/collection.rb +37 -0
- data/lib/ticketing_hub/configuration.rb +6 -12
- data/lib/ticketing_hub/connection.rb +1 -1
- data/lib/ticketing_hub/error.rb +15 -0
- data/lib/ticketing_hub/request.rb +25 -50
- data/lib/ticketing_hub/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f21a9e16f1bd59df8cbee7c6e932fc51158548b
|
4
|
+
data.tar.gz: 44d6029b5eb3ca276003259a78cb90ff9f1cde07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27abe8ac329b8365d4312088e1751bffbfb1d844310e84dadcee601d38ac9331187187d89ffe1cb529a1b1f1574595b34dfcb6f47fd9e0ca64f5b582c237bbdb
|
7
|
+
data.tar.gz: c14c25c3022ca477efd30430dd39aac59d380659a051bd7cecb31707fd1742910c09af00934284214b86f0d2f42cf75fd4b08b82e38952826180684587fe52be
|
data/lib/ticketing_hub/client.rb
CHANGED
@@ -8,72 +8,63 @@ module TicketingHub
|
|
8
8
|
|
9
9
|
attr_accessor *Configuration::VALID_OPTIONS_KEYS
|
10
10
|
|
11
|
-
def
|
11
|
+
def self.from_oauth_password(email, password)
|
12
|
+
token = TicketingHub.post 'oauth/token', { grant_type: 'password', username: email, password: password,
|
13
|
+
client_id: TicketingHub.client_id, client_secret: TicketingHub.client_secret }
|
14
|
+
new(access_token: token.access_token, refresh_token: token.refresh_token, expires_at: Time.now + token.expires_in)
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(options={})
|
12
18
|
options = TicketingHub.options.merge options
|
13
19
|
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
14
20
|
send "#{key}=", options[key]
|
15
21
|
end
|
16
22
|
end
|
17
23
|
|
18
|
-
def
|
19
|
-
|
20
|
-
client_secret: client_secret, code: code, endpoint: oauth_endpoint)['access_token']
|
21
|
-
end
|
22
|
-
|
23
|
-
def venue id=nil
|
24
|
-
id ? get("venues/#{id}") : get('venue')
|
24
|
+
def venues
|
25
|
+
get 'venues'
|
25
26
|
end
|
26
27
|
|
27
28
|
def user
|
28
|
-
get
|
29
|
+
get('user').first
|
29
30
|
end
|
30
31
|
|
31
|
-
def orders
|
32
|
-
venue_id ||= venue(venue_id).id
|
32
|
+
def orders(venue_id=nil)
|
33
33
|
get "venues/#{venue_id}/orders"
|
34
34
|
end
|
35
35
|
|
36
|
-
def
|
37
|
-
get "orders/#{
|
36
|
+
def find_order(venue_id=nil, id)
|
37
|
+
get "venues/#{venue_id}/orders/#{id}"
|
38
38
|
end
|
39
39
|
|
40
|
-
def tiers date, time,
|
41
|
-
venue_id
|
42
|
-
get "venues/#{venue_id}/tiers", { date: date, time: time }
|
40
|
+
def tiers(venue_id, date, time, options = {})
|
41
|
+
get "venues/#{venue_id}/tiers", options.merge({ date: date, time: time })
|
43
42
|
end
|
44
43
|
|
45
|
-
def seasons
|
46
|
-
venue_id ||= venue(venue_id).id
|
44
|
+
def seasons(venue_id)
|
47
45
|
get "venues/#{venue_id}/seasons"
|
48
46
|
end
|
49
47
|
|
50
|
-
def customer_fields order_id, ticket_id=nil
|
51
|
-
ticket_id.nil?? get("orders/#{
|
52
|
-
get("tickets/#{
|
48
|
+
def customer_fields(venue_id, order_id, ticket_id=nil)
|
49
|
+
ticket_id.nil?? get("venues/#{venue_id}/orders/#{order_id}/fields") :
|
50
|
+
get("venues/#{venue_id}/tickets/#{ticket_id}/fields")
|
53
51
|
end
|
54
52
|
|
55
|
-
def create_order
|
56
|
-
venue_id
|
57
|
-
post "venues/#{venue_id}/orders", order_attributes
|
53
|
+
def create_order(venue_id, date, time, order_attributes = {})
|
54
|
+
post "venues/#{venue_id}/orders", order_attributes.merge(date: date, time: time)
|
58
55
|
end
|
59
56
|
|
60
|
-
def cancel_order order_id
|
61
|
-
delete "orders/#{
|
57
|
+
def cancel_order(venue_id, order_id)
|
58
|
+
delete "venues/#{venue_id}/orders/#{order_id}"
|
62
59
|
end
|
63
60
|
|
64
|
-
def update_order order_id, order_attributes
|
65
|
-
patch "orders/#{
|
61
|
+
def update_order(venue_id, order_id, order_attributes)
|
62
|
+
patch "venues/#{venue_id}/orders/#{order_id}", order_attributes
|
66
63
|
end
|
67
64
|
|
68
|
-
def confirm_order order_id, order_attributes=
|
69
|
-
update_order order_id, order_attributes if order_attributes
|
70
|
-
post "orders/#{
|
65
|
+
def confirm_order(venue_id, order_id, order_attributes = {})
|
66
|
+
update_order venue_id, order_id, order_attributes if order_attributes.any?
|
67
|
+
post "venues/#{venue_id}/orders/#{order_id}/confirm"
|
71
68
|
end
|
72
|
-
|
73
|
-
private
|
74
|
-
|
75
|
-
def _normalize_object_id object_id
|
76
|
-
(object_id.is_a?(Hash) ? object_id['id'] : object_id).to_i
|
77
|
-
end
|
78
69
|
end
|
79
70
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module TicketingHub
|
2
|
+
class Collection < Enumerator::Generator
|
3
|
+
|
4
|
+
attr_accessor :client, :path, :options
|
5
|
+
|
6
|
+
def initialize(client, path, options = {})
|
7
|
+
self.client = client
|
8
|
+
self.path = path
|
9
|
+
self.options = options
|
10
|
+
|
11
|
+
super() do |yielder|
|
12
|
+
response = client.request(:get, path, options)
|
13
|
+
if response.body.is_a?(Array)
|
14
|
+
response.body.each { |value| yielder << value }
|
15
|
+
else yielder << response.body end
|
16
|
+
while next_url = links(response)['next']
|
17
|
+
client.request(:get, next_url, options).body.each do |value|
|
18
|
+
yielder << value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def find(id, options = {})
|
25
|
+
client.request(:get, "#{path}/#{id}", options).body
|
26
|
+
end
|
27
|
+
|
28
|
+
def links(response)
|
29
|
+
links = ( response.headers["Link"] || "" ).split(', ').map do |link|
|
30
|
+
url, type = link.match(/<(.*?)>; rel="(\w+)"/).captures
|
31
|
+
[ type, url ]
|
32
|
+
end
|
33
|
+
|
34
|
+
Hash[*links.flatten]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -7,23 +7,19 @@ module TicketingHub
|
|
7
7
|
VALID_OPTIONS_KEYS = [
|
8
8
|
:adapter,
|
9
9
|
:faraday_config_block,
|
10
|
-
:api_version,
|
11
10
|
:api_endpoint,
|
12
|
-
:oauth_endpoint,
|
13
11
|
:client_id,
|
14
12
|
:client_secret,
|
15
|
-
:
|
13
|
+
:access_token,
|
14
|
+
:refresh_token,
|
15
|
+
:expires_at,
|
16
16
|
:proxy,
|
17
17
|
:user_agent,
|
18
|
-
:request_host
|
19
|
-
:auto_traversal].freeze
|
18
|
+
:request_host].freeze
|
20
19
|
|
21
20
|
DEFAULT_ADAPTER = Faraday.default_adapter
|
22
|
-
DEFAULT_API_VERSION = 1
|
23
21
|
DEFAULT_API_ENDPOINT = ENV['TH_API_ENDPOINT'] || 'https://api.ticketinghub.com/'
|
24
|
-
DEFAULT_OAUTH_ENDPOINT = ENV['TH_OAUTH_ENDPOINT'] || 'https://www.ticketinghub.com/oauth/'
|
25
22
|
DEFAULT_USER_AGENT = "TicketingHub Ruby Gem #{TicketingHub::VERSION}".freeze
|
26
|
-
DEFAULT_AUTO_TRAVERSAL = false
|
27
23
|
|
28
24
|
attr_accessor *VALID_OPTIONS_KEYS
|
29
25
|
|
@@ -51,16 +47,14 @@ module TicketingHub
|
|
51
47
|
|
52
48
|
def reset
|
53
49
|
self.adapter = DEFAULT_ADAPTER
|
54
|
-
self.api_version = DEFAULT_API_VERSION
|
55
50
|
self.api_endpoint = DEFAULT_API_ENDPOINT
|
56
|
-
self.oauth_endpoint = DEFAULT_OAUTH_ENDPOINT
|
57
51
|
self.client_id = nil
|
58
52
|
self.client_secret = nil
|
59
|
-
self.
|
53
|
+
self.access_token = nil
|
54
|
+
self.refresh_token = nil
|
60
55
|
self.proxy = nil
|
61
56
|
self.request_host = nil
|
62
57
|
self.user_agent = DEFAULT_USER_AGENT
|
63
|
-
self.auto_traversal = DEFAULT_AUTO_TRAVERSAL
|
64
58
|
end
|
65
59
|
end
|
66
60
|
end
|
data/lib/ticketing_hub/error.rb
CHANGED
@@ -9,6 +9,21 @@ module TicketingHub
|
|
9
9
|
def response_body
|
10
10
|
@response[:body]
|
11
11
|
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def build_error_message
|
15
|
+
return nil if @response.nil?
|
16
|
+
|
17
|
+
message = if response_body
|
18
|
+
": #{response_body[:error] || response_body[:error_message] || ''}"
|
19
|
+
else
|
20
|
+
''
|
21
|
+
end
|
22
|
+
errors = unless message.empty?
|
23
|
+
response_body[:errors] ? ": #{response_body[:errors].map{|e|e[:error_message]}.join(', ')}" : ''
|
24
|
+
end
|
25
|
+
"#{@response[:method].to_s.upcase} #{@response[:url].to_s}: #{@response[:status]}#{message}#{errors}"
|
26
|
+
end
|
12
27
|
end
|
13
28
|
|
14
29
|
# Raised when TicketingHub returns a 400 HTTP status code
|
@@ -1,78 +1,53 @@
|
|
1
1
|
require 'multi_json'
|
2
|
+
require_relative 'collection'
|
2
3
|
|
3
4
|
module TicketingHub
|
4
5
|
module Request
|
5
6
|
|
6
|
-
def delete
|
7
|
+
def delete(path, options={})
|
7
8
|
request(:delete, path, options).body
|
8
9
|
end
|
9
10
|
|
10
|
-
def get
|
11
|
-
|
12
|
-
body = response.body
|
13
|
-
|
14
|
-
if auto_traversal && body.is_a?(Array)
|
15
|
-
while next_url = links(response)['next']
|
16
|
-
response = request(:get, next_url, options)
|
17
|
-
body += response.body
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
body
|
11
|
+
def get(path, options={})
|
12
|
+
TicketingHub::Collection.new self, path, options
|
22
13
|
end
|
23
14
|
|
24
|
-
def patch
|
15
|
+
def patch(path, options={})
|
25
16
|
request(:patch, path, options).body
|
26
17
|
end
|
27
18
|
|
28
|
-
def post
|
19
|
+
def post(path, options={})
|
29
20
|
request(:post, path, options).body
|
30
21
|
end
|
31
22
|
|
32
|
-
def put
|
23
|
+
def put(path, options={})
|
33
24
|
request(:put, path, options).body
|
34
25
|
end
|
35
26
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
# @return [Boolean] True on success, false otherwise
|
41
|
-
def boolean_from_response(method, path, options={})
|
42
|
-
request(method, path, options).status == 204
|
43
|
-
rescue TicketingHub::NotFound
|
44
|
-
false
|
45
|
-
end
|
46
|
-
|
47
|
-
def request(method, path, options={})
|
48
|
-
force_urlencoded = options.delete(:force_urlencoded) || false
|
49
|
-
url = options.delete(:endpoint) || api_endpoint
|
50
|
-
conn_options = { force_urlencoded: force_urlencoded, url: url }
|
27
|
+
def request(method, path, options={})
|
28
|
+
force_urlencoded = options.delete(:force_urlencoded) || false
|
29
|
+
url = options.delete(:endpoint) || api_endpoint
|
30
|
+
conn_options = { force_urlencoded: force_urlencoded, url: url }
|
51
31
|
|
52
|
-
|
53
|
-
|
32
|
+
connection(conn_options).send(method) do |request|
|
33
|
+
case method
|
54
34
|
when :get, :delete, :head
|
55
35
|
request.url(path, options)
|
56
36
|
when :patch, :post, :put
|
57
37
|
request.path = path
|
58
|
-
unless options.empty?
|
59
|
-
request.body = force_urlencoded ? options : MultiJson.dump(options)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
if TicketingHub.request_host
|
64
|
-
request.headers['Host'] = TicketingHub.request_host
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def links(response)
|
70
|
-
links = ( response.headers["Link"] || "" ).split(', ').map do |link|
|
71
|
-
url, type = link.match(/<(.*?)>; rel="(\w+)"/).captures
|
72
|
-
[ type, url ]
|
38
|
+
request.body = force_urlencoded ? options : MultiJson.dump(options) unless options.empty?
|
73
39
|
end
|
74
|
-
|
75
|
-
Hash[ *links.flatten ]
|
40
|
+
request.headers['Host'] = TicketingHub.request_host if TicketingHub.request_host
|
76
41
|
end
|
42
|
+
rescue TicketingHub::Unauthorized => e
|
43
|
+
if refresh_token.present? && e.response_body == ' '
|
44
|
+
body = post '/oauth/token', { grant_type: 'refresh_token',
|
45
|
+
refresh_token: refresh_token, client_id: client_id, client_secret: client_secret }
|
46
|
+
self.refresh_token = body.refresh_token
|
47
|
+
self.access_token = body.access_token
|
48
|
+
self.expires_at = Time.now + body.expires_in.to_i
|
49
|
+
request(method, path, options)
|
50
|
+
else throw e end
|
77
51
|
end
|
52
|
+
end
|
78
53
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ticketinghub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oliver Morgan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -107,6 +107,7 @@ files:
|
|
107
107
|
- Rakefile
|
108
108
|
- ticketinghub.gemspec
|
109
109
|
- lib/ticketing_hub/client.rb
|
110
|
+
- lib/ticketing_hub/collection.rb
|
110
111
|
- lib/ticketing_hub/configuration.rb
|
111
112
|
- lib/ticketing_hub/connection.rb
|
112
113
|
- lib/ticketing_hub/error.rb
|