ticketevolution-ruby 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +8 -0
- data/.rdebugrc +1 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +7 -0
- data/LICENSE +23 -0
- data/README.markdown +237 -0
- data/Rakefile +124 -0
- data/examples/events.rb +64 -0
- data/lib/docs/endpoints.markdown +47 -0
- data/lib/docs/installation.markdown +5 -0
- data/lib/docs/introduction.markdown +16 -0
- data/lib/docs/objects.markdown +40 -0
- data/lib/ticket_evolution/account.rb +4 -0
- data/lib/ticket_evolution/accounts.rb +6 -0
- data/lib/ticket_evolution/address.rb +4 -0
- data/lib/ticket_evolution/brokerage.rb +4 -0
- data/lib/ticket_evolution/brokerages.rb +7 -0
- data/lib/ticket_evolution/categories.rb +7 -0
- data/lib/ticket_evolution/category.rb +4 -0
- data/lib/ticket_evolution/client.rb +4 -0
- data/lib/ticket_evolution/clients/addresses.rb +10 -0
- data/lib/ticket_evolution/clients/credit_cards.rb +8 -0
- data/lib/ticket_evolution/clients/email_addresses.rb +10 -0
- data/lib/ticket_evolution/clients/phone_numbers.rb +10 -0
- data/lib/ticket_evolution/clients.rb +8 -0
- data/lib/ticket_evolution/configuration.rb +4 -0
- data/lib/ticket_evolution/configurations.rb +6 -0
- data/lib/ticket_evolution/core/api_error.rb +11 -0
- data/lib/ticket_evolution/core/base.rb +12 -0
- data/lib/ticket_evolution/core/builder.rb +74 -0
- data/lib/ticket_evolution/core/collection.rb +32 -0
- data/lib/ticket_evolution/core/connection.rb +99 -0
- data/lib/ticket_evolution/core/datum.rb +7 -0
- data/lib/ticket_evolution/core/endpoint/request_handler.rb +46 -0
- data/lib/ticket_evolution/core/endpoint.rb +51 -0
- data/lib/ticket_evolution/core/model.rb +64 -0
- data/lib/ticket_evolution/core/models/samples.rb +8 -0
- data/lib/ticket_evolution/core/samples.rb +6 -0
- data/lib/ticket_evolution/core/singular_class.rb +7 -0
- data/lib/ticket_evolution/core/time.rb +19 -0
- data/lib/ticket_evolution/credit_card.rb +4 -0
- data/lib/ticket_evolution/email_address.rb +4 -0
- data/lib/ticket_evolution/errors/connection_not_found.rb +4 -0
- data/lib/ticket_evolution/errors/endpoint_configuration_error.rb +5 -0
- data/lib/ticket_evolution/errors/invalid_configuration.rb +4 -0
- data/lib/ticket_evolution/errors/method_unavailable_error.rb +4 -0
- data/lib/ticket_evolution/event.rb +4 -0
- data/lib/ticket_evolution/events.rb +7 -0
- data/lib/ticket_evolution/modules/create.rb +18 -0
- data/lib/ticket_evolution/modules/deleted.rb +13 -0
- data/lib/ticket_evolution/modules/list.rb +15 -0
- data/lib/ticket_evolution/modules/search.rb +13 -0
- data/lib/ticket_evolution/modules/show.rb +20 -0
- data/lib/ticket_evolution/modules/update.rb +24 -0
- data/lib/ticket_evolution/office.rb +4 -0
- data/lib/ticket_evolution/offices.rb +7 -0
- data/lib/ticket_evolution/order.rb +15 -0
- data/lib/ticket_evolution/orders.rb +30 -0
- data/lib/ticket_evolution/performer.rb +4 -0
- data/lib/ticket_evolution/performers.rb +8 -0
- data/lib/ticket_evolution/phone_number.rb +4 -0
- data/lib/ticket_evolution/quote.rb +4 -0
- data/lib/ticket_evolution/quotes.rb +7 -0
- data/lib/ticket_evolution/search.rb +22 -0
- data/lib/ticket_evolution/shipment.rb +4 -0
- data/lib/ticket_evolution/shipments.rb +8 -0
- data/lib/ticket_evolution/ticket_group.rb +4 -0
- data/lib/ticket_evolution/ticket_groups.rb +6 -0
- data/lib/ticket_evolution/user.rb +4 -0
- data/lib/ticket_evolution/users.rb +7 -0
- data/lib/ticket_evolution/venue.rb +4 -0
- data/lib/ticket_evolution/venues.rb +8 -0
- data/lib/ticket_evolution/version.rb +3 -0
- data/lib/ticket_evolution.rb +108 -0
- data/spec/fixtures/fake.rb +97 -0
- data/spec/fixtures/net/endpoints/accounts.yml +175 -0
- data/spec/fixtures/net/endpoints/brokerages.yml +257 -0
- data/spec/fixtures/net/endpoints/categories.yml +85 -0
- data/spec/fixtures/net/endpoints/clients.yml +243 -0
- data/spec/fixtures/net/endpoints/search.yml +93 -0
- data/spec/lib/ticket_evolution/account_spec.rb +7 -0
- data/spec/lib/ticket_evolution/accounts_spec.rb +45 -0
- data/spec/lib/ticket_evolution/address_spec.rb +7 -0
- data/spec/lib/ticket_evolution/brokerage_spec.rb +7 -0
- data/spec/lib/ticket_evolution/brokerages_spec.rb +50 -0
- data/spec/lib/ticket_evolution/categories_spec.rb +27 -0
- data/spec/lib/ticket_evolution/category_spec.rb +7 -0
- data/spec/lib/ticket_evolution/client_spec.rb +7 -0
- data/spec/lib/ticket_evolution/clients/addresses_spec.rb +13 -0
- data/spec/lib/ticket_evolution/clients/credit_cards_spec.rb +11 -0
- data/spec/lib/ticket_evolution/clients/email_addresses_spec.rb +13 -0
- data/spec/lib/ticket_evolution/clients/phone_numbers_spec.rb +13 -0
- data/spec/lib/ticket_evolution/clients_spec.rb +37 -0
- data/spec/lib/ticket_evolution/configuration_spec.rb +7 -0
- data/spec/lib/ticket_evolution/configurations_spec.rb +10 -0
- data/spec/lib/ticket_evolution/core/api_error_spec.rb +13 -0
- data/spec/lib/ticket_evolution/core/base_spec.rb +29 -0
- data/spec/lib/ticket_evolution/core/builder_spec.rb +95 -0
- data/spec/lib/ticket_evolution/core/collection_spec.rb +23 -0
- data/spec/lib/ticket_evolution/core/connection_spec.rb +220 -0
- data/spec/lib/ticket_evolution/core/datum_spec.rb +15 -0
- data/spec/lib/ticket_evolution/core/endpoint_spec.rb +12 -0
- data/spec/lib/ticket_evolution/core/model_spec.rb +167 -0
- data/spec/lib/ticket_evolution/core/time_spec.rb +28 -0
- data/spec/lib/ticket_evolution/credit_card_spec.rb +7 -0
- data/spec/lib/ticket_evolution/email_address_spec.rb +7 -0
- data/spec/lib/ticket_evolution/errors/connection_not_found_spec.rb +7 -0
- data/spec/lib/ticket_evolution/errors/endpoint_configuration_error_spec.rb +8 -0
- data/spec/lib/ticket_evolution/errors/invalid_configuration_spec.rb +8 -0
- data/spec/lib/ticket_evolution/errors/method_unavailable_error_spec.rb +7 -0
- data/spec/lib/ticket_evolution/event_spec.rb +7 -0
- data/spec/lib/ticket_evolution/events_spec.rb +11 -0
- data/spec/lib/ticket_evolution/office_spec.rb +7 -0
- data/spec/lib/ticket_evolution/offices_spec.rb +11 -0
- data/spec/lib/ticket_evolution/order_spec.rb +44 -0
- data/spec/lib/ticket_evolution/orders_spec.rb +123 -0
- data/spec/lib/ticket_evolution/performer_spec.rb +7 -0
- data/spec/lib/ticket_evolution/performers_spec.rb +12 -0
- data/spec/lib/ticket_evolution/phone_number_spec.rb +7 -0
- data/spec/lib/ticket_evolution/quote_spec.rb +7 -0
- data/spec/lib/ticket_evolution/quotes_spec.rb +11 -0
- data/spec/lib/ticket_evolution/search_spec.rb +31 -0
- data/spec/lib/ticket_evolution/shipment_spec.rb +7 -0
- data/spec/lib/ticket_evolution/shipments_spec.rb +13 -0
- data/spec/lib/ticket_evolution/ticket_group_spec.rb +7 -0
- data/spec/lib/ticket_evolution/ticket_groups_spec.rb +14 -0
- data/spec/lib/ticket_evolution/user_spec.rb +7 -0
- data/spec/lib/ticket_evolution/users_spec.rb +15 -0
- data/spec/lib/ticket_evolution/venue_spec.rb +7 -0
- data/spec/lib/ticket_evolution/venues_spec.rb +12 -0
- data/spec/lib/ticket_evolution_spec.rb +20 -0
- data/spec/shared_examples/endpoints/class.rb +241 -0
- data/spec/shared_examples/endpoints/create.rb +41 -0
- data/spec/shared_examples/endpoints/deleted.rb +41 -0
- data/spec/shared_examples/endpoints/list.rb +41 -0
- data/spec/shared_examples/endpoints/search.rb +42 -0
- data/spec/shared_examples/endpoints/show.rb +38 -0
- data/spec/shared_examples/endpoints/update.rb +59 -0
- data/spec/shared_examples/errors.rb +5 -0
- data/spec/shared_examples/models.rb +29 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/support/connection.rb +10 -0
- data/spec/support/vcr.rb +12 -0
- data/ticketevolution-ruby.gemspec +33 -0
- metadata +384 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe TicketEvolution::Accounts do
|
|
4
|
+
let(:klass) { TicketEvolution::Accounts }
|
|
5
|
+
let(:single_klass) { TicketEvolution::Account }
|
|
6
|
+
|
|
7
|
+
it_behaves_like 'a ticket_evolution endpoint class'
|
|
8
|
+
it_behaves_like 'a list endpoint'
|
|
9
|
+
it_behaves_like 'a show endpoint'
|
|
10
|
+
|
|
11
|
+
context "integration tests" do
|
|
12
|
+
use_vcr_cassette "endpoints/accounts", :record => :new_episodes
|
|
13
|
+
|
|
14
|
+
it "returns an account" do
|
|
15
|
+
id = 62
|
|
16
|
+
account = connection.accounts.show(id)
|
|
17
|
+
|
|
18
|
+
account.url.should == "/accounts/#{id}"
|
|
19
|
+
account.currency.should == "USD"
|
|
20
|
+
account.updated_at.should_not be_nil
|
|
21
|
+
account.balance.should == "9922.71"
|
|
22
|
+
account.id.should == id.to_s
|
|
23
|
+
|
|
24
|
+
account.client.should == TicketEvolution::Client.new({
|
|
25
|
+
:connection => connection,
|
|
26
|
+
"url" => "/clients/3",
|
|
27
|
+
"name" => "Main Office",
|
|
28
|
+
"id" => "3"
|
|
29
|
+
})
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "returns a list of accounts" do
|
|
33
|
+
accounts = connection.accounts.list(:per_page => 4, :page => 5)
|
|
34
|
+
|
|
35
|
+
accounts.per_page.should == 4
|
|
36
|
+
accounts.current_page.should == 5
|
|
37
|
+
accounts.total_entries.should == 88
|
|
38
|
+
|
|
39
|
+
accounts.size.should == 4
|
|
40
|
+
accounts.each do |account|
|
|
41
|
+
account.should be_a TicketEvolution::Account
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe TicketEvolution::Brokerages do
|
|
4
|
+
let(:klass) { TicketEvolution::Brokerages }
|
|
5
|
+
let(:single_klass) { TicketEvolution::Brokerage }
|
|
6
|
+
|
|
7
|
+
it_behaves_like 'a ticket_evolution endpoint class'
|
|
8
|
+
it_behaves_like 'a list endpoint'
|
|
9
|
+
it_behaves_like 'a search endpoint'
|
|
10
|
+
it_behaves_like 'a show endpoint'
|
|
11
|
+
|
|
12
|
+
context "integration tests" do
|
|
13
|
+
use_vcr_cassette "endpoints/brokerages", :record => :new_episodes
|
|
14
|
+
|
|
15
|
+
it "returns a brokerage" do
|
|
16
|
+
brokerage = connection.brokerages.show(2)
|
|
17
|
+
|
|
18
|
+
brokerage.should be_a TicketEvolution::Brokerage
|
|
19
|
+
brokerage.name.should == "Golden Tickets"
|
|
20
|
+
brokerage.id.should == "2"
|
|
21
|
+
brokerage.url.should == "/brokerages/2"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "returns a list of brokerages" do
|
|
25
|
+
brokerages = connection.brokerages.list(:per_page => 3, :page => 4)
|
|
26
|
+
|
|
27
|
+
brokerages.per_page.should == 3
|
|
28
|
+
brokerages.current_page.should == 4
|
|
29
|
+
brokerages.total_entries.should == 1379
|
|
30
|
+
|
|
31
|
+
brokerages.size.should == 3
|
|
32
|
+
brokerages.each do |brokerage|
|
|
33
|
+
brokerage.should be_a TicketEvolution::Brokerage
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "searches for a brokerage" do
|
|
38
|
+
brokerages = connection.brokerages.search(:q => "New York", "page" => 1)
|
|
39
|
+
|
|
40
|
+
# FIXME: The search API doesn't return total entries, yet (due to lack of pagination)...
|
|
41
|
+
brokerages.per_page.should be_nil
|
|
42
|
+
brokerages.current_page.should be_nil
|
|
43
|
+
brokerages.total_entries.should be_nil
|
|
44
|
+
|
|
45
|
+
brokerages.count.should == 2
|
|
46
|
+
brokerages.each { |brokerage| brokerage.should be_an_instance_of TicketEvolution::Brokerage }
|
|
47
|
+
brokerages.first.name.should == "Totally New York"
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe TicketEvolution::Categories do
|
|
4
|
+
let(:klass) { TicketEvolution::Categories }
|
|
5
|
+
let(:single_klass) { TicketEvolution::Category }
|
|
6
|
+
|
|
7
|
+
it_behaves_like 'a ticket_evolution endpoint class'
|
|
8
|
+
it_behaves_like 'a deleted endpoint'
|
|
9
|
+
it_behaves_like 'a list endpoint'
|
|
10
|
+
it_behaves_like 'a show endpoint'
|
|
11
|
+
|
|
12
|
+
describe "integrations" do
|
|
13
|
+
use_vcr_cassette "endpoints/categories", :record => :new_episodes
|
|
14
|
+
|
|
15
|
+
context "#deleted" do
|
|
16
|
+
it "returns a list of deleted categories" do
|
|
17
|
+
categories = connection.categories.deleted(:per_page => 2)
|
|
18
|
+
|
|
19
|
+
categories.size.should == 1
|
|
20
|
+
categories.each do |category|
|
|
21
|
+
category.should be_instance_of TicketEvolution::Category
|
|
22
|
+
end
|
|
23
|
+
categories.first.name.should == "Insult Comedy"
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe TicketEvolution::Clients::Addresses do
|
|
4
|
+
let(:klass) { TicketEvolution::Clients::Addresses }
|
|
5
|
+
let(:single_klass) { TicketEvolution::Address }
|
|
6
|
+
let(:update_base) { {'url' => '/clients/1/addresses/1'} }
|
|
7
|
+
|
|
8
|
+
it_behaves_like 'a ticket_evolution endpoint class'
|
|
9
|
+
it_behaves_like 'a create endpoint'
|
|
10
|
+
it_behaves_like 'a list endpoint'
|
|
11
|
+
it_behaves_like 'a show endpoint'
|
|
12
|
+
it_behaves_like 'an update endpoint'
|
|
13
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe TicketEvolution::Clients::CreditCards do
|
|
4
|
+
let(:klass) { TicketEvolution::Clients::CreditCards }
|
|
5
|
+
let(:single_klass) { TicketEvolution::CreditCard }
|
|
6
|
+
let(:update_base) { {'url' => '/clients/1/credit_cards/1'} }
|
|
7
|
+
|
|
8
|
+
it_behaves_like 'a ticket_evolution endpoint class'
|
|
9
|
+
it_behaves_like 'a create endpoint'
|
|
10
|
+
it_behaves_like 'a list endpoint'
|
|
11
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe TicketEvolution::Clients::EmailAddresses do
|
|
4
|
+
let(:klass) { TicketEvolution::Clients::EmailAddresses }
|
|
5
|
+
let(:single_klass) { TicketEvolution::EmailAddress }
|
|
6
|
+
let(:update_base) { {'url' => '/clients/1/email_addresses/1'} }
|
|
7
|
+
|
|
8
|
+
it_behaves_like 'a ticket_evolution endpoint class'
|
|
9
|
+
it_behaves_like 'a create endpoint'
|
|
10
|
+
it_behaves_like 'a list endpoint'
|
|
11
|
+
it_behaves_like 'a show endpoint'
|
|
12
|
+
it_behaves_like 'an update endpoint'
|
|
13
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe TicketEvolution::Clients::PhoneNumbers do
|
|
4
|
+
let(:klass) { TicketEvolution::Clients::PhoneNumbers }
|
|
5
|
+
let(:single_klass) { TicketEvolution::PhoneNumber }
|
|
6
|
+
let(:update_base) { {'url' => '/clients/1/phone_numbers/1'} }
|
|
7
|
+
|
|
8
|
+
it_behaves_like 'a ticket_evolution endpoint class'
|
|
9
|
+
it_behaves_like 'a create endpoint'
|
|
10
|
+
it_behaves_like 'a list endpoint'
|
|
11
|
+
it_behaves_like 'a show endpoint'
|
|
12
|
+
it_behaves_like 'an update endpoint'
|
|
13
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe TicketEvolution::Clients do
|
|
4
|
+
let(:klass) { TicketEvolution::Clients }
|
|
5
|
+
let(:single_klass) { TicketEvolution::Client }
|
|
6
|
+
let(:update_base) { {} }
|
|
7
|
+
|
|
8
|
+
it_behaves_like 'a ticket_evolution endpoint class'
|
|
9
|
+
it_behaves_like 'a create endpoint'
|
|
10
|
+
it_behaves_like 'a list endpoint'
|
|
11
|
+
it_behaves_like 'a show endpoint'
|
|
12
|
+
it_behaves_like 'an update endpoint'
|
|
13
|
+
|
|
14
|
+
describe "integrations" do
|
|
15
|
+
use_vcr_cassette "endpoints/clients", :record => :new_episodes, :match_requests_on => [:method, :uri, :body]
|
|
16
|
+
|
|
17
|
+
context "#create" do
|
|
18
|
+
it "returns validation errors" do
|
|
19
|
+
client = connection.clients.create(:name => "")
|
|
20
|
+
client.should be_an_instance_of TicketEvolution::ApiError
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "successfully creates a client" do
|
|
24
|
+
name = "Comish Gordon"
|
|
25
|
+
client = connection.clients.create(:name => name)
|
|
26
|
+
|
|
27
|
+
client.should be_instance_of TicketEvolution::Client
|
|
28
|
+
client.id.should be
|
|
29
|
+
client.name.should == name
|
|
30
|
+
|
|
31
|
+
same_client = connection.clients.show(client.id)
|
|
32
|
+
same_client.id.should == client.id
|
|
33
|
+
same_client.name.should == name
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe TicketEvolution::Configurations do
|
|
4
|
+
let(:klass) { TicketEvolution::Configurations }
|
|
5
|
+
let(:single_klass) { TicketEvolution::Configuration }
|
|
6
|
+
|
|
7
|
+
it_behaves_like 'a ticket_evolution endpoint class'
|
|
8
|
+
it_behaves_like 'a list endpoint'
|
|
9
|
+
it_behaves_like 'a show endpoint'
|
|
10
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe TicketEvolution::ApiError do
|
|
4
|
+
let(:klass) { TicketEvolution::ApiError }
|
|
5
|
+
let(:response) { Fake.error_response }
|
|
6
|
+
let(:instance) { klass.new(response) }
|
|
7
|
+
|
|
8
|
+
subject { instance }
|
|
9
|
+
|
|
10
|
+
its(:error) { should == response.body['error'] }
|
|
11
|
+
its(:code) { should == response.response_code }
|
|
12
|
+
its(:message) { should == response.server_message }
|
|
13
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe TicketEvolution::Base do
|
|
4
|
+
let(:klass) { TicketEvolution::Base }
|
|
5
|
+
let(:sample_klass) { TicketEvolution::Samples }
|
|
6
|
+
let(:base) { klass.new }
|
|
7
|
+
|
|
8
|
+
describe "#method_missing" do
|
|
9
|
+
it "should attempt to find a class which matches the missing method" do
|
|
10
|
+
TicketEvolution.should_receive(:const_defined?).with(:NoObjects)
|
|
11
|
+
expect { base.no_objects }.to raise_error
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
context "when the missing class is found" do
|
|
15
|
+
it "should instantiate a new instance of the class, passing itself to initialize as :parent" do
|
|
16
|
+
instance = sample_klass.new({:parent => base})
|
|
17
|
+
sample_klass.should_receive(:new).with({:parent => base}).and_return(instance)
|
|
18
|
+
base.samples.should be_a sample_klass
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
context "when the missing class is not found" do
|
|
23
|
+
it "should perform as if the method doesn't exist" do
|
|
24
|
+
message = "undefined method `coconuts' for #{base.inspect}"
|
|
25
|
+
expect { base.coconuts }.to raise_error NoMethodError, message
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe TicketEvolution::Builder do
|
|
4
|
+
let(:klass) { TicketEvolution::Builder }
|
|
5
|
+
let(:instance) { klass.new(params) }
|
|
6
|
+
let(:params) { {} }
|
|
7
|
+
|
|
8
|
+
subject { klass }
|
|
9
|
+
|
|
10
|
+
its(:ancestors) { should include OpenStruct }
|
|
11
|
+
|
|
12
|
+
describe "#initialize" do
|
|
13
|
+
let(:params) do
|
|
14
|
+
{
|
|
15
|
+
"url" => "/brokerages/2",
|
|
16
|
+
"natb_member" => true,
|
|
17
|
+
"name" => "Golden Tickets",
|
|
18
|
+
"id" => "2",
|
|
19
|
+
"abbreviation" => "Golden Tickets"
|
|
20
|
+
}
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "should assign each key value pair as attributes" do
|
|
24
|
+
params.keys.each do |key|
|
|
25
|
+
instance.send(key).should == params[key]
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "should call #process_datum for each attribute assigned" do
|
|
30
|
+
params.values.each do |v|
|
|
31
|
+
klass.any_instance.should_receive(:process_datum).with(v)
|
|
32
|
+
end
|
|
33
|
+
instance
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
describe "#process_datum" do
|
|
38
|
+
let(:time) { "2011-12-18T17:30:06Z" }
|
|
39
|
+
|
|
40
|
+
context "when dealing with a string" do
|
|
41
|
+
context "formatted as time" do
|
|
42
|
+
it "should convert the string to a TicketEvolution::Time object" do
|
|
43
|
+
instance.send(:process_datum, time).should == TicketEvolution::Time.parse(time)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
context "when dealing with a hash" do
|
|
49
|
+
it "should instantiate a new TicketEvolution::Datum object" do
|
|
50
|
+
instance.send(:process_datum, {:one => 1}).should be_a TicketEvolution::Datum
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
context "when dealing with an array" do
|
|
55
|
+
it "should map arrays, calling itself on each value" do
|
|
56
|
+
instance.send(:process_datum, [{:one => 1}, time]).should == [
|
|
57
|
+
TicketEvolution::Datum.new({:one => 1}),
|
|
58
|
+
TicketEvolution::Time.parse(time)
|
|
59
|
+
]
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
describe "#class_name_from_url" do
|
|
65
|
+
it "extracts a TicketEvolution class name from a url, searching segments right to left" do
|
|
66
|
+
{
|
|
67
|
+
'/events' => 'TicketEvolution::Events',
|
|
68
|
+
'/events/12' => 'TicketEvolution::Events',
|
|
69
|
+
'/events/deleted' => 'TicketEvolution::Events',
|
|
70
|
+
'/events/21/venues/12' => 'TicketEvolution::Venues'
|
|
71
|
+
}.each do |given, expected|
|
|
72
|
+
instance.send(:class_name_from_url, given).should == expected
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
describe "#method_missing" do
|
|
78
|
+
let(:params) { {} }
|
|
79
|
+
|
|
80
|
+
describe "with args" do
|
|
81
|
+
it "should invoke #process_datum with the information received" do
|
|
82
|
+
instance.should_receive(:process_datum).with(:ing)
|
|
83
|
+
instance.test = :ing
|
|
84
|
+
instance.should_receive(:process_datum).with([1,2])
|
|
85
|
+
instance.array = [1,2]
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
describe "without args" do
|
|
90
|
+
it "should fall back on the OpenStruct#method_missing functionality" do
|
|
91
|
+
instance.test.should == nil
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe TicketEvolution::Collection do
|
|
4
|
+
subject { TicketEvolution::Collection.build_from_response(response, 'brokerages', TicketEvolution::Brokerage) }
|
|
5
|
+
let(:response) { Fake.list_response }
|
|
6
|
+
|
|
7
|
+
context "#build_from_response" do
|
|
8
|
+
it { should be_instance_of(TicketEvolution::Collection) }
|
|
9
|
+
it { should be_kind_of(Enumerable) }
|
|
10
|
+
its(:per_page) { should == 2 }
|
|
11
|
+
its(:total_entries) { should == 1379 }
|
|
12
|
+
its(:current_page) { should == 1 }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
context "#each" do
|
|
16
|
+
it "iterates through all the entries" do
|
|
17
|
+
subject.size.should == 2
|
|
18
|
+
subject.each do |entry|
|
|
19
|
+
entry.should be_instance_of TicketEvolution::Brokerage
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe TicketEvolution::Connection do
|
|
4
|
+
let(:klass) { TicketEvolution::Connection }
|
|
5
|
+
let(:default_options) do
|
|
6
|
+
HashWithIndifferentAccess.new({
|
|
7
|
+
:version => klass.oldest_version_in_service,
|
|
8
|
+
:mode => :sandbox,
|
|
9
|
+
:ssl_verify => true
|
|
10
|
+
})
|
|
11
|
+
end
|
|
12
|
+
let(:basic_options) do
|
|
13
|
+
{
|
|
14
|
+
:token => Fake.token,
|
|
15
|
+
:secret => Fake.secret
|
|
16
|
+
}
|
|
17
|
+
end
|
|
18
|
+
let(:valid_options) { default_options.merge(basic_options) }
|
|
19
|
+
|
|
20
|
+
subject { klass }
|
|
21
|
+
|
|
22
|
+
its(:ancestors) { should include TicketEvolution::Base }
|
|
23
|
+
|
|
24
|
+
describe ".default_options" do
|
|
25
|
+
subject { klass.default_options }
|
|
26
|
+
|
|
27
|
+
it { should == default_options }
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe ".expected_options" do
|
|
31
|
+
subject { klass.expected_options }
|
|
32
|
+
|
|
33
|
+
it { should =~ valid_options.keys }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe ".oldest_version_in_service" do
|
|
37
|
+
subject { klass.oldest_version_in_service }
|
|
38
|
+
|
|
39
|
+
it { should be_a Fixnum }
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
describe "#initialize" do
|
|
43
|
+
let(:expected_options) { klass.expected_options }
|
|
44
|
+
|
|
45
|
+
context "with valid options" do
|
|
46
|
+
it "should copy to options passed to the default options" do
|
|
47
|
+
klass.new(basic_options).instance_eval {
|
|
48
|
+
@config
|
|
49
|
+
}.should == valid_options
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
context "with ssl_verify" do
|
|
54
|
+
context "if passed" do
|
|
55
|
+
let(:options) { valid_options.merge(:ssl_verify => false) }
|
|
56
|
+
|
|
57
|
+
it "sets the Curl::Easy to that value" do
|
|
58
|
+
connection = klass.new(options)
|
|
59
|
+
easy = connection.build_request(:GET, '/')
|
|
60
|
+
easy.ssl_verify_host?.should be_false
|
|
61
|
+
easy.ssl_verify_peer?.should be_false
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
context "if not passed" do
|
|
66
|
+
it "does not set anything on the Curl::Easy object" do
|
|
67
|
+
connection = klass.new(valid_options)
|
|
68
|
+
easy = connection.build_request(:GET, '/')
|
|
69
|
+
easy.ssl_verify_host?.should be_true
|
|
70
|
+
easy.ssl_verify_peer?.should be_true
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
context "without any options" do
|
|
76
|
+
it "should raise an error notifying the user of the missing options" do
|
|
77
|
+
message = "Missing: #{(expected_options - default_options.keys).join(', ')}"
|
|
78
|
+
expect {
|
|
79
|
+
klass.new
|
|
80
|
+
}.to raise_error TicketEvolution::InvalidConfiguration, message
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
context "with invalid options" do
|
|
85
|
+
it "should raise an error if the token is not formatted correctly" do
|
|
86
|
+
expect {
|
|
87
|
+
klass.new(valid_options.merge({:token => "invalid"}))
|
|
88
|
+
}.to raise_error TicketEvolution::InvalidConfiguration, "Invalid Token Format"
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "should raise an error if the token is not formatted correctly" do
|
|
92
|
+
expect {
|
|
93
|
+
klass.new(valid_options.merge({:secret => "invalid"}))
|
|
94
|
+
}.to raise_error TicketEvolution::InvalidConfiguration, "Invalid Secret Format"
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "should raise an error if attempting to use an expired version" do
|
|
98
|
+
oldest_version = klass.oldest_version_in_service - 1
|
|
99
|
+
expect {
|
|
100
|
+
klass.new(valid_options.merge({:version => oldest_version}))
|
|
101
|
+
}.to raise_error TicketEvolution::InvalidConfiguration, "Please Use API Version #{klass.oldest_version_in_service} or Above"
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it "should not error if bad options are passed in" do
|
|
105
|
+
expect {
|
|
106
|
+
klass.new(valid_options.merge(:invalid => :option))
|
|
107
|
+
}.to_not raise_error
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
describe ".url_base" do
|
|
113
|
+
subject { klass.url_base }
|
|
114
|
+
|
|
115
|
+
it { should == "ticketevolution.com" }
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
describe ".protocol" do
|
|
119
|
+
subject { klass.protocol }
|
|
120
|
+
|
|
121
|
+
it { should == "https" }
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
describe "#url" do
|
|
125
|
+
context "production" do
|
|
126
|
+
subject { klass.new(valid_options.merge({:mode => :production}))}
|
|
127
|
+
|
|
128
|
+
its(:url) { should == "https://api.ticketevolution.com" }
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
context "sandbox" do
|
|
132
|
+
subject { klass.new(valid_options) }
|
|
133
|
+
|
|
134
|
+
its(:url) { should == "https://api.sandbox.ticketevolution.com" }
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
describe "#sign" do
|
|
139
|
+
let(:path) { "/test" }
|
|
140
|
+
|
|
141
|
+
describe "without params" do
|
|
142
|
+
let(:connection) { klass.new(valid_options.merge({:secret => "/3uZ9bXNe/6rxEBmlGLvoRXrcSzRDMfyJSewhlrc"})) }
|
|
143
|
+
|
|
144
|
+
it "should sign a get request" do
|
|
145
|
+
connection.sign(:GET, path).should == "1Ra2c8cbuw1G5Pw8BWaowDlMcxwMte8y/sL+vW2H4mY="
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
it "should sign a post request" do
|
|
149
|
+
connection.sign(:POST, path).should == "pXqUawURysCxiIvPXCgTaQ1k5Nue0bAVHIyhrxJRmI0="
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
it "should sign a put request" do
|
|
153
|
+
connection.sign(:PUT, path).should == "+INyuqXHZv3+ybyGM/mQIJVJ6RslR/xUAmcauZnHWBo="
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it "should sign a delete request" do
|
|
157
|
+
connection.sign(:DELETE, path).should == "Mwr4Z+hveuo8ITaYwaRQ/QdxYotpw97ZH1JfJmblVQY="
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
describe "with params" do
|
|
162
|
+
let(:params) do
|
|
163
|
+
if RUBY_VERSION =~ /^1\.9/
|
|
164
|
+
{
|
|
165
|
+
:one => 1,
|
|
166
|
+
:two => "two",
|
|
167
|
+
:three => :three
|
|
168
|
+
}
|
|
169
|
+
else
|
|
170
|
+
p = ActiveSupport::OrderedHash.new
|
|
171
|
+
p[:one] = 1
|
|
172
|
+
p[:two] = "two"
|
|
173
|
+
p[:three] = "three"
|
|
174
|
+
p
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
let(:connection) { klass.new(valid_options.merge({:secret => "/3uZ9bXNe/6rxEBmlGLvoRXrcSzRDMfyJSewhlrc"})) }
|
|
178
|
+
|
|
179
|
+
it "should sign a get request" do
|
|
180
|
+
connection.sign(:GET, path, params).should == "8eaaqg6d4DJ2SEWkCvkdhc05dITmpNbUrcbN75UBGMA="
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
it "should sign a post request" do
|
|
184
|
+
connection.sign(:POST, path, params).should == "6PMaU8JQ5kH4PZLl8agJrZRZqnn65UGcCUA80E2dTDg="
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
it "should sign a put request" do
|
|
188
|
+
connection.sign(:PUT, path, params).should == "JEwlN3cuRXnb6rQlaorVYtlbGbBQRXs792YGQaH5BoM="
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
it "should sign a delete request" do
|
|
192
|
+
connection.sign(:DELETE, path, params).should == "aHXaOzCmuVttO2qSnaH5Ku4SN2q/ukoxz2FIbCRWmeY="
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
describe "#build_request" do
|
|
198
|
+
let(:headers) do
|
|
199
|
+
{
|
|
200
|
+
"Accept" => "application/vnd.ticketevolution.api+json; version=#{valid_options[:version]}",
|
|
201
|
+
"X-Signature" => "8eaaqg6d4DJ2SEWkCvkdhc05dITmpNbUrcbN75UBGMA=",
|
|
202
|
+
"X-Token" => valid_options[:token]
|
|
203
|
+
}
|
|
204
|
+
end
|
|
205
|
+
let(:params) do
|
|
206
|
+
{
|
|
207
|
+
:one => 1,
|
|
208
|
+
:two => "two",
|
|
209
|
+
:three => :three
|
|
210
|
+
}
|
|
211
|
+
end
|
|
212
|
+
let(:url) { "https://api.sandbox.ticketevolution.com/test?one=1&three=three&two=two" }
|
|
213
|
+
|
|
214
|
+
subject { klass.new(valid_options.merge(:secret => "/3uZ9bXNe/6rxEBmlGLvoRXrcSzRDMfyJSewhlrc")).build_request(:GET, '/test', params) }
|
|
215
|
+
|
|
216
|
+
it { should be_a Curl::Easy }
|
|
217
|
+
its(:headers) { should == headers }
|
|
218
|
+
its(:url) { should == url }
|
|
219
|
+
end
|
|
220
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe TicketEvolution::Datum do
|
|
4
|
+
let(:klass) { TicketEvolution::Datum }
|
|
5
|
+
let(:instance) { klass.new }
|
|
6
|
+
|
|
7
|
+
subject { klass }
|
|
8
|
+
|
|
9
|
+
its(:ancestors) { should include TicketEvolution::Builder }
|
|
10
|
+
|
|
11
|
+
it "should respond to []" do
|
|
12
|
+
instance.test = :testing
|
|
13
|
+
instance[:test].should == :testing
|
|
14
|
+
end
|
|
15
|
+
end
|