ticketevolution-ruby 0.7.11 → 0.7.16
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ext/hash.rb +1 -0
- data/lib/faraday/localhost_header.rb +36 -0
- data/lib/ticket_evolution.rb +15 -1
- data/lib/ticket_evolution/accounts/transactions.rb +8 -0
- data/lib/ticket_evolution/address.rb +4 -0
- data/lib/ticket_evolution/clients.rb +4 -0
- data/lib/ticket_evolution/clients/addresses.rb +14 -0
- data/lib/ticket_evolution/clients/credit_cards.rb +2 -0
- data/lib/ticket_evolution/core/collection.rb +5 -3
- data/lib/ticket_evolution/core/connection.rb +3 -0
- data/lib/ticket_evolution/core/model.rb +1 -0
- data/lib/ticket_evolution/core/model/parental_behavior.rb +3 -1
- data/lib/ticket_evolution/modules/destroy.rb +1 -1
- data/lib/ticket_evolution/offices/credit_cards.rb +10 -0
- data/lib/ticket_evolution/order.rb +8 -0
- data/lib/ticket_evolution/orders.rb +27 -0
- data/lib/ticket_evolution/orders/payments.rb +8 -0
- data/lib/ticket_evolution/payment.rb +4 -0
- data/lib/ticket_evolution/service_fee.rb +4 -0
- data/lib/ticket_evolution/settings.rb +42 -0
- data/lib/ticket_evolution/shipping_setting.rb +4 -0
- data/lib/ticket_evolution/taken_ticket.rb +4 -0
- data/lib/ticket_evolution/{transactions.rb → taken_tickets.rb} +1 -2
- data/lib/ticket_evolution/ticket_group.rb +15 -0
- data/lib/ticket_evolution/ticket_groups.rb +30 -0
- data/lib/ticket_evolution/ticket_groups/ticket_holds.rb +7 -0
- data/lib/ticket_evolution/ticket_hold.rb +4 -0
- data/lib/ticket_evolution/version.rb +1 -1
- data/spec/fixtures/fake.rb +30 -0
- data/spec/fixtures/net/endpoints/settings.yml +80 -0
- data/spec/fixtures/net/endpoints/settings_service_fees.yml +41 -0
- data/spec/lib/ext/hash_spec.rb +9 -0
- data/spec/lib/faraday/localhost_header_spec.rb +61 -0
- data/spec/lib/ticket_evolution/{transactions_spec.rb → accounts/transactions_spec.rb} +2 -2
- data/spec/lib/ticket_evolution/clients/addresses_spec.rb +13 -0
- data/spec/lib/ticket_evolution/clients_spec.rb +11 -0
- data/spec/lib/ticket_evolution/core/collection_spec.rb +79 -29
- data/spec/lib/ticket_evolution/core/model_spec.rb +6 -0
- data/spec/lib/ticket_evolution/offices/credit_cards_spec.rb +12 -0
- data/spec/lib/ticket_evolution/orders/payments_spec.rb +10 -0
- data/spec/lib/ticket_evolution/orders_spec.rb +11 -0
- data/spec/lib/ticket_evolution/payment_spec.rb +7 -0
- data/spec/lib/ticket_evolution/service_fee_spec.rb +7 -0
- data/spec/lib/ticket_evolution/settings_spec.rb +32 -0
- data/spec/lib/ticket_evolution/shipping_setting_spec.rb +7 -0
- data/spec/lib/ticket_evolution/taken_tickets_spec.rb +12 -0
- data/spec/lib/ticket_evolution/ticket_group_spec.rb +41 -0
- data/spec/lib/ticket_evolution/ticket_groups/ticket_holds_spec.rb +9 -0
- data/spec/lib/ticket_evolution/ticket_groups_spec.rb +45 -0
- data/spec/lib/ticket_evolution/ticket_hold_spec.rb +7 -0
- data/spec/shared_examples/endpoints/destroy.rb +0 -1
- metadata +61 -26
data/lib/ext/hash.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Faraday request middleware that processes requests made to domains such as
|
2
|
+
# *.lvh.me or *.xip.io. When encountering one, it swaps out the hostname with
|
3
|
+
# the raw IP, but populates the 'Host' request HTTP header with the original
|
4
|
+
# hostname.
|
5
|
+
#
|
6
|
+
# This enables usage of lvh.me and xip.io domains even when their DNS service
|
7
|
+
# is down, because it completely circumvents any DNS lookup.
|
8
|
+
class FaradayLocalhostHeader
|
9
|
+
attr_reader :app, :patterns
|
10
|
+
|
11
|
+
HOST = 'Host'.freeze
|
12
|
+
HOME = '127.0.0.1'
|
13
|
+
|
14
|
+
def initialize app, patterns
|
15
|
+
@app = app
|
16
|
+
@patterns = Array(patterns)
|
17
|
+
end
|
18
|
+
|
19
|
+
def call env
|
20
|
+
detect_domain_hack env[:url] do |hostname, ip|
|
21
|
+
env[:url].host = ip
|
22
|
+
env[:request_headers][HOST] = hostname
|
23
|
+
end
|
24
|
+
app.call env
|
25
|
+
end
|
26
|
+
|
27
|
+
def detect_domain_hack url
|
28
|
+
patterns.each do |re|
|
29
|
+
if url.host =~ re
|
30
|
+
ip = $1 ? $1.chomp('.') : HOME
|
31
|
+
yield url.host, ip
|
32
|
+
return
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/ticket_evolution.rb
CHANGED
@@ -76,15 +76,20 @@ i.req 'company'
|
|
76
76
|
i.req 'client'
|
77
77
|
i.req 'configuration'
|
78
78
|
i.req 'credit_card'
|
79
|
+
i.req 'ticket_hold'
|
79
80
|
i.req 'email_address'
|
80
81
|
i.req 'event'
|
81
82
|
i.req 'office'
|
82
83
|
i.req 'order'
|
84
|
+
i.req 'payment'
|
83
85
|
i.req 'performer'
|
84
86
|
i.req 'phone_number'
|
85
87
|
i.req 'quote'
|
86
88
|
i.req 'rate_option'
|
89
|
+
i.req 'service_fee'
|
87
90
|
i.req 'shipment'
|
91
|
+
i.req 'shipping_setting'
|
92
|
+
i.req 'taken_ticket'
|
88
93
|
i.req 'ticket_group'
|
89
94
|
i.req 'track_detail'
|
90
95
|
i.req 'transaction'
|
@@ -104,10 +109,11 @@ i.req 'orders'
|
|
104
109
|
i.req 'performers'
|
105
110
|
i.req 'quotes'
|
106
111
|
i.req 'rate_options'
|
112
|
+
i.req 'settings'
|
107
113
|
i.req 'shipments'
|
114
|
+
i.req 'taken_tickets'
|
108
115
|
i.req 'ticket_groups'
|
109
116
|
i.req 'track_details'
|
110
|
-
i.req 'transactions'
|
111
117
|
i.req 'users'
|
112
118
|
i.req 'venues'
|
113
119
|
i.req 'search'
|
@@ -116,3 +122,11 @@ i.req 'clients', 'addresses'
|
|
116
122
|
i.req 'clients', 'credit_cards'
|
117
123
|
i.req 'clients', 'email_addresses'
|
118
124
|
i.req 'clients', 'phone_numbers'
|
125
|
+
|
126
|
+
i.req 'accounts', 'transactions'
|
127
|
+
|
128
|
+
i.req 'offices', 'credit_cards'
|
129
|
+
|
130
|
+
i.req 'orders', 'payments'
|
131
|
+
|
132
|
+
i.req 'ticket_groups', 'ticket_holds'
|
@@ -4,5 +4,9 @@ module TicketEvolution
|
|
4
4
|
include TicketEvolution::Modules::List
|
5
5
|
include TicketEvolution::Modules::Show
|
6
6
|
include TicketEvolution::Modules::Update
|
7
|
+
|
8
|
+
def create_from_office(params = nil)
|
9
|
+
request(:POST, "/create_from_office/#{params[:office_id]}", nil, &method(:build_for_show))
|
10
|
+
end
|
7
11
|
end
|
8
12
|
end
|
@@ -6,6 +6,20 @@ module TicketEvolution
|
|
6
6
|
include TicketEvolution::Modules::Show
|
7
7
|
include TicketEvolution::Modules::Update
|
8
8
|
include TicketEvolution::Modules::Destroy
|
9
|
+
|
10
|
+
def fedex_check(id, params=nil, &handler)
|
11
|
+
handler ||= method(:fedex_check_handler)
|
12
|
+
request(:GET, "/#{id}/fedex_check", nil, &handler)
|
13
|
+
end
|
14
|
+
|
15
|
+
def fedex_check_handler(response)
|
16
|
+
singular_class.new(response.body.merge({
|
17
|
+
:status_code => response.response_code,
|
18
|
+
:server_message => response.server_message,
|
19
|
+
:connection => response.body[:connection]
|
20
|
+
}))
|
21
|
+
end
|
22
|
+
|
9
23
|
end
|
10
24
|
end
|
11
25
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module TicketEvolution
|
2
2
|
class Collection
|
3
|
-
attr_accessor :total_entries, :per_page, :current_page, :entries, :status_code
|
3
|
+
attr_accessor :total_entries, :per_page, :current_page, :entries, :status_code, :unique_categories
|
4
4
|
|
5
5
|
include Enumerable
|
6
6
|
|
@@ -15,7 +15,7 @@ module TicketEvolution
|
|
15
15
|
|
16
16
|
def self.build_from_response(response, entries_key, singular_class)
|
17
17
|
entries = response.body[entries_key] || []
|
18
|
-
|
18
|
+
values = {
|
19
19
|
:status_code => response.response_code,
|
20
20
|
:total_entries => response.body['total_entries'],
|
21
21
|
:per_page => response.body['per_page'],
|
@@ -23,7 +23,9 @@ module TicketEvolution
|
|
23
23
|
:entries => entries.collect do |entry|
|
24
24
|
singular_class.new(entry.merge({:connection => response.body[:connection]}))
|
25
25
|
end
|
26
|
-
|
26
|
+
}
|
27
|
+
values[:unique_categories] = response.body['unique_categories'] if response.body['unique_categories']
|
28
|
+
new(values)
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'faraday/localhost_header'
|
2
|
+
|
1
3
|
module TicketEvolution
|
2
4
|
class Connection < Base
|
3
5
|
cattr_reader :default_options, :expected_options, :oldest_version_in_service
|
@@ -82,6 +84,7 @@ module TicketEvolution
|
|
82
84
|
options[:headers]["Accept"] = "application/vnd.ticketevolution.api+json; version=#{@config[:version]}" unless @config[:version] > 8
|
83
85
|
Faraday.new(self.uri(path), options) do |builder|
|
84
86
|
builder.use Faraday::Response::VerboseLogger, self.logger if self.logger.present?
|
87
|
+
builder.use FaradayLocalhostHeader, [ /(?:^|\.)lvh\.me$/i, /(?:^|\.)((?:\d+\.){4})xip\.io$/i ]
|
85
88
|
builder.adapter @adapter
|
86
89
|
end
|
87
90
|
end
|
@@ -63,6 +63,7 @@ module TicketEvolution
|
|
63
63
|
|
64
64
|
def method_missing(method, *args)
|
65
65
|
begin
|
66
|
+
method = method.to_s.gsub("_endpoint", "") if method.to_s.end_with? "_endpoint"
|
66
67
|
"#{plural_class_name}::#{method.to_s.camelize}".constantize.new(:parent => plural_class.new(:parent => @connection, :id => self.id))
|
67
68
|
rescue
|
68
69
|
super
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module TicketEvolution
|
2
|
+
class Offices
|
3
|
+
class CreditCards < TicketEvolution::Endpoint
|
4
|
+
include TicketEvolution::Modules::Create
|
5
|
+
include TicketEvolution::Modules::List
|
6
|
+
include TicketEvolution::Modules::Update
|
7
|
+
include TicketEvolution::Modules::Destroy
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -11,5 +11,13 @@ module TicketEvolution
|
|
11
11
|
def reject(params)
|
12
12
|
plural_class.new(:parent => @connection).reject_order(params)
|
13
13
|
end
|
14
|
+
|
15
|
+
def email(params)
|
16
|
+
plural_class.new(:parent => @connection,:id => self.id).email_order(params)
|
17
|
+
end
|
18
|
+
|
19
|
+
def print
|
20
|
+
plural_class.new(:parent => @connection,:id => self.id).print_order
|
21
|
+
end
|
14
22
|
end
|
15
23
|
end
|
@@ -9,6 +9,10 @@ module TicketEvolution
|
|
9
9
|
alias :create_client_order :create
|
10
10
|
alias :create_customer_order :create
|
11
11
|
|
12
|
+
def balance(params = nil)
|
13
|
+
request(:GET, '/balance', params, &method(:build_for_show))
|
14
|
+
end
|
15
|
+
|
12
16
|
def accept_order(params = nil)
|
13
17
|
ensure_id
|
14
18
|
request(:POST, "/#{self.id}/accept", params, &method(:build_for_create))
|
@@ -27,5 +31,28 @@ module TicketEvolution
|
|
27
31
|
ensure_id
|
28
32
|
request(:POST, "/#{self.id}/complete", nil, &method(:build_for_create))
|
29
33
|
end
|
34
|
+
|
35
|
+
def email_order(params = nil)
|
36
|
+
ensure_id
|
37
|
+
request(:POST, "/email", params) do |response|
|
38
|
+
singular_class.new(response.body.merge({
|
39
|
+
:status_code => response.response_code,
|
40
|
+
:server_message => response.server_message,
|
41
|
+
:connection => response.body[:connection]
|
42
|
+
}))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def print_order
|
47
|
+
ensure_id
|
48
|
+
request(:GET, "/print", nil) do |response|
|
49
|
+
singular_class.new(response.body.merge({
|
50
|
+
:status_code => response.response_code,
|
51
|
+
:server_message => response.server_message,
|
52
|
+
:connection => response.body[:connection]
|
53
|
+
}))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
30
57
|
end
|
31
58
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module TicketEvolution
|
2
|
+
class Settings < Endpoint
|
3
|
+
def shipping(params = {})
|
4
|
+
request(:GET, "/shipping", params, &method(:build_for_shipping))
|
5
|
+
end
|
6
|
+
|
7
|
+
def build_for_shipping(response)
|
8
|
+
collection = TicketEvolution::Collection.new(
|
9
|
+
:total_entries => response.body['total_entries']
|
10
|
+
)
|
11
|
+
|
12
|
+
response.body['settings'].each do |result|
|
13
|
+
collection.entries << "TicketEvolution::ShippingSetting".
|
14
|
+
constantize.new(result.merge({:connection => connection}))
|
15
|
+
end
|
16
|
+
|
17
|
+
collection
|
18
|
+
end
|
19
|
+
|
20
|
+
def service_fees(params = {})
|
21
|
+
request(:GET, "/service_fees", params, &method(:build_for_service_fees))
|
22
|
+
end
|
23
|
+
|
24
|
+
def build_for_service_fees(response)
|
25
|
+
collection = TicketEvolution::Collection.new(
|
26
|
+
:total_entries => response.body['total_entries']
|
27
|
+
)
|
28
|
+
|
29
|
+
response.body['settings'].each do |result|
|
30
|
+
collection.entries << "TicketEvolution::ServiceFee".
|
31
|
+
constantize.new(result.merge({:connection => connection}))
|
32
|
+
end
|
33
|
+
|
34
|
+
collection
|
35
|
+
end
|
36
|
+
|
37
|
+
def singular_class(klass = self.class)
|
38
|
+
TicketEvolution::ShippingSetting
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
@@ -1,4 +1,19 @@
|
|
1
1
|
module TicketEvolution
|
2
2
|
class TicketGroup < Model
|
3
|
+
def hold(params)
|
4
|
+
plural_class.new(:parent => @connection, :id => self.id).hold(params)
|
5
|
+
end
|
6
|
+
def take(params)
|
7
|
+
plural_class.new(:parent => @connection, :id => self.id).take(params)
|
8
|
+
end
|
9
|
+
def release_hold(params)
|
10
|
+
plural_class.new(:parent => @connection, :id => self.id).release_hold(params)
|
11
|
+
end
|
12
|
+
def waste(params)
|
13
|
+
plural_class.new(:parent => @connection, :id => self.id).waste(params)
|
14
|
+
end
|
15
|
+
def toggle_broadcast(params)
|
16
|
+
plural_class.new(:parent => @connection, :id => self.id).toggle_broadcast(params)
|
17
|
+
end
|
3
18
|
end
|
4
19
|
end
|
@@ -2,5 +2,35 @@ module TicketEvolution
|
|
2
2
|
class TicketGroups < Endpoint
|
3
3
|
include TicketEvolution::Modules::List
|
4
4
|
include TicketEvolution::Modules::Show
|
5
|
+
include TicketEvolution::Modules::Update
|
6
|
+
|
7
|
+
def hold(params = nil)
|
8
|
+
ensure_id
|
9
|
+
request(:POST, "/hold", params, &method(:build_for_show))
|
10
|
+
end
|
11
|
+
|
12
|
+
def take(params = nil)
|
13
|
+
ensure_id
|
14
|
+
request(:POST, "/take", params, &method(:build_for_show))
|
15
|
+
end
|
16
|
+
def release_hold(params = nil)
|
17
|
+
ensure_id
|
18
|
+
request(:POST, "/release_hold/#{params[:ticket_hold_id]}", nil, &method(:build_for_show))
|
19
|
+
end
|
20
|
+
|
21
|
+
def waste(params = nil)
|
22
|
+
ensure_id
|
23
|
+
request(:POST, "/waste", params, &method(:build_for_show))
|
24
|
+
end
|
25
|
+
|
26
|
+
def toggle_broadcast(params = nil)
|
27
|
+
ensure_id
|
28
|
+
request(:POST, "/broadcast", params, &method(:build_for_show))
|
29
|
+
end
|
30
|
+
|
31
|
+
def index_cart(ids = [])
|
32
|
+
handler ||= method(:collection_handler)
|
33
|
+
request(:GET, '/index_cart', ids, &handler)
|
34
|
+
end
|
5
35
|
end
|
6
36
|
end
|