tito_ruby 0.1.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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +12 -0
- data/LICENSE.txt +21 -0
- data/README.md +119 -0
- data/lib/tito/admin/client.rb +98 -0
- data/lib/tito/admin/collection_proxy.rb +119 -0
- data/lib/tito/admin/query_builder.rb +110 -0
- data/lib/tito/admin/resources/activity.rb +32 -0
- data/lib/tito/admin/resources/answer.rb +23 -0
- data/lib/tito/admin/resources/checkin_list.rb +34 -0
- data/lib/tito/admin/resources/discount_code.rb +36 -0
- data/lib/tito/admin/resources/event.rb +62 -0
- data/lib/tito/admin/resources/interested_user.rb +19 -0
- data/lib/tito/admin/resources/opt_in.rb +23 -0
- data/lib/tito/admin/resources/question.rb +30 -0
- data/lib/tito/admin/resources/refund.rb +20 -0
- data/lib/tito/admin/resources/registration.rb +49 -0
- data/lib/tito/admin/resources/release.rb +67 -0
- data/lib/tito/admin/resources/release_invitation.rb +32 -0
- data/lib/tito/admin/resources/rsvp_list.rb +26 -0
- data/lib/tito/admin/resources/ticket.rb +59 -0
- data/lib/tito/admin/resources/venue.rb +19 -0
- data/lib/tito/admin/resources/waitlisted_person.rb +35 -0
- data/lib/tito/admin/resources/webhook_endpoint.rb +20 -0
- data/lib/tito/admin/scope.rb +71 -0
- data/lib/tito/configuration.rb +9 -0
- data/lib/tito/connection.rb +42 -0
- data/lib/tito/errors.rb +40 -0
- data/lib/tito/resource.rb +172 -0
- data/lib/tito/types/integer_array.rb +15 -0
- data/lib/tito/types/json.rb +16 -0
- data/lib/tito/types/string_array.rb +15 -0
- data/lib/tito/version.rb +3 -0
- data/lib/tito.rb +63 -0
- data/lib/tito_ruby.rb +1 -0
- metadata +180 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Tito
|
|
2
|
+
module Admin
|
|
3
|
+
module Resources
|
|
4
|
+
class InterestedUser < Tito::Resource
|
|
5
|
+
event_scoped!
|
|
6
|
+
path_template "%{account}/%{event}/interested_users"
|
|
7
|
+
resource_name "interested_user"
|
|
8
|
+
collection_name "interested_users"
|
|
9
|
+
supports :list, :show, :create, :update, :delete
|
|
10
|
+
|
|
11
|
+
attribute :id, :integer
|
|
12
|
+
attribute :email, :string
|
|
13
|
+
attribute :name, :string
|
|
14
|
+
attribute :created_at, :datetime
|
|
15
|
+
attribute :updated_at, :datetime
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Tito
|
|
2
|
+
module Admin
|
|
3
|
+
module Resources
|
|
4
|
+
class OptIn < Tito::Resource
|
|
5
|
+
event_scoped!
|
|
6
|
+
path_template "%{account}/%{event}/opt_ins"
|
|
7
|
+
resource_name "opt_in"
|
|
8
|
+
collection_name "opt_ins"
|
|
9
|
+
supports :list, :show, :create, :update, :delete
|
|
10
|
+
|
|
11
|
+
attribute :id, :integer
|
|
12
|
+
attribute :slug, :string
|
|
13
|
+
attribute :name, :string
|
|
14
|
+
attribute :description, :string
|
|
15
|
+
attribute :acceptance_count, :integer
|
|
16
|
+
attribute :created_at, :datetime
|
|
17
|
+
attribute :updated_at, :datetime
|
|
18
|
+
|
|
19
|
+
expandable :releases
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Tito
|
|
2
|
+
module Admin
|
|
3
|
+
module Resources
|
|
4
|
+
class Question < Tito::Resource
|
|
5
|
+
event_scoped!
|
|
6
|
+
path_template "%{account}/%{event}/questions"
|
|
7
|
+
resource_name "question"
|
|
8
|
+
collection_name "questions"
|
|
9
|
+
supports :list, :show, :create, :update, :delete
|
|
10
|
+
|
|
11
|
+
attribute :id, :integer
|
|
12
|
+
attribute :slug, :string
|
|
13
|
+
attribute :title, :string
|
|
14
|
+
attribute :description, :string
|
|
15
|
+
attribute :field_type, :string
|
|
16
|
+
attribute :options, :string
|
|
17
|
+
attribute :include_free_text_field, :boolean
|
|
18
|
+
attribute :required, :boolean
|
|
19
|
+
attribute :answers_count, :integer
|
|
20
|
+
attribute :tickets_count, :integer
|
|
21
|
+
attribute :created_at, :datetime
|
|
22
|
+
attribute :updated_at, :datetime
|
|
23
|
+
|
|
24
|
+
expandable :activities, :releases
|
|
25
|
+
|
|
26
|
+
has_many :answers, resource_class_name: "Answer"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Tito
|
|
2
|
+
module Admin
|
|
3
|
+
module Resources
|
|
4
|
+
class Refund < Tito::Resource
|
|
5
|
+
event_scoped!
|
|
6
|
+
path_template "%{account}/%{event}/registrations/%{parent_id}/refunds"
|
|
7
|
+
resource_name "refund"
|
|
8
|
+
collection_name "refunds"
|
|
9
|
+
supports :list, :show
|
|
10
|
+
|
|
11
|
+
attribute :id, :integer
|
|
12
|
+
attribute :amount, :decimal
|
|
13
|
+
attribute :manual, :boolean
|
|
14
|
+
attribute :created_at, :datetime
|
|
15
|
+
|
|
16
|
+
expandable :registration
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
module Tito
|
|
2
|
+
module Admin
|
|
3
|
+
module Resources
|
|
4
|
+
class Registration < Tito::Resource
|
|
5
|
+
event_scoped!
|
|
6
|
+
path_template "%{account}/%{event}/registrations"
|
|
7
|
+
resource_name "registration"
|
|
8
|
+
collection_name "registrations"
|
|
9
|
+
supports :list, :show, :create, :update
|
|
10
|
+
|
|
11
|
+
attribute :id, :integer
|
|
12
|
+
attribute :slug, :string
|
|
13
|
+
attribute :reference, :string
|
|
14
|
+
attribute :email, :string
|
|
15
|
+
attribute :name, :string
|
|
16
|
+
attribute :phone_number, :string
|
|
17
|
+
attribute :job_title, :string
|
|
18
|
+
attribute :company_name, :string
|
|
19
|
+
attribute :payment_reference, :string
|
|
20
|
+
attribute :total, :decimal
|
|
21
|
+
attribute :total_less_tax, :decimal
|
|
22
|
+
attribute :paid, :boolean
|
|
23
|
+
attribute :payment_complete, :boolean
|
|
24
|
+
attribute :payment_incomplete, :boolean
|
|
25
|
+
attribute :cancelled, :boolean
|
|
26
|
+
attribute :cancelled_at, :datetime
|
|
27
|
+
attribute :completed_at, :datetime
|
|
28
|
+
attribute :consented_at, :datetime
|
|
29
|
+
attribute :locale, :string
|
|
30
|
+
attribute :metadata, :string
|
|
31
|
+
attribute :discount_code_id, :integer
|
|
32
|
+
attribute :imported, :boolean
|
|
33
|
+
attribute :manual, :boolean
|
|
34
|
+
attribute :test_mode, :boolean
|
|
35
|
+
attribute :created_at, :datetime
|
|
36
|
+
attribute :updated_at, :datetime
|
|
37
|
+
|
|
38
|
+
expandable :billing_address, :receipts, :refunds, :tickets, :line_items
|
|
39
|
+
|
|
40
|
+
action :confirm!, method: :post, path: "confirmations"
|
|
41
|
+
action :unconfirm!, method: :delete, path: "confirmations"
|
|
42
|
+
action :refund!, method: :post, path: "refunds"
|
|
43
|
+
action :cancel!, method: :post, path: "cancellation"
|
|
44
|
+
|
|
45
|
+
has_many :refunds, resource_class_name: "Refund"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
module Tito
|
|
2
|
+
module Admin
|
|
3
|
+
module Resources
|
|
4
|
+
class Release < Tito::Resource
|
|
5
|
+
event_scoped!
|
|
6
|
+
path_template "%{account}/%{event}/releases"
|
|
7
|
+
resource_name "release"
|
|
8
|
+
collection_name "releases"
|
|
9
|
+
supports :list, :show, :create, :update, :delete
|
|
10
|
+
|
|
11
|
+
attribute :id, :integer
|
|
12
|
+
attribute :slug, :string
|
|
13
|
+
attribute :title, :string
|
|
14
|
+
attribute :description, :string
|
|
15
|
+
attribute :event_id, :integer
|
|
16
|
+
attribute :price, :decimal
|
|
17
|
+
attribute :price_ex_tax, :decimal
|
|
18
|
+
attribute :display_price, :string
|
|
19
|
+
attribute :payment_type, :string
|
|
20
|
+
attribute :quantity, :integer
|
|
21
|
+
attribute :tickets_count, :integer
|
|
22
|
+
attribute :allocatable, :integer
|
|
23
|
+
attribute :sold_out, :boolean
|
|
24
|
+
attribute :archived, :boolean
|
|
25
|
+
attribute :off_sale, :boolean
|
|
26
|
+
attribute :locked, :boolean
|
|
27
|
+
attribute :expired, :boolean
|
|
28
|
+
attribute :upcoming, :boolean
|
|
29
|
+
attribute :secret, :boolean
|
|
30
|
+
attribute :not_a_ticket, :boolean
|
|
31
|
+
attribute :lock_changes, :boolean
|
|
32
|
+
attribute :only_issue_combos, :boolean
|
|
33
|
+
attribute :card_payments, :boolean
|
|
34
|
+
attribute :invoice, :boolean
|
|
35
|
+
attribute :donation, :boolean
|
|
36
|
+
attribute :require_email, :boolean
|
|
37
|
+
attribute :require_name, :boolean
|
|
38
|
+
attribute :require_billing_address, :boolean
|
|
39
|
+
attribute :require_company_name, :boolean
|
|
40
|
+
attribute :require_vat_number, :boolean
|
|
41
|
+
attribute :show_price, :boolean
|
|
42
|
+
attribute :show_qr_code, :boolean
|
|
43
|
+
attribute :show_discount_code_field_here, :boolean
|
|
44
|
+
attribute :max_tickets_per_person, :integer
|
|
45
|
+
attribute :min_tickets_per_person, :integer
|
|
46
|
+
attribute :start_at, :datetime
|
|
47
|
+
attribute :end_at, :datetime
|
|
48
|
+
attribute :success_message, :string
|
|
49
|
+
attribute :fail_message, :string
|
|
50
|
+
attribute :metadata, :string
|
|
51
|
+
attribute :tax_exclusive, :boolean
|
|
52
|
+
attribute :created_at, :datetime
|
|
53
|
+
attribute :updated_at, :datetime
|
|
54
|
+
|
|
55
|
+
expandable :activities, :activity_questions, :combo_releases, :questions, :super_combo_releases, :tax_components, :tax_types, :termset, :ticket_group
|
|
56
|
+
|
|
57
|
+
action :archive!, method: :post, path: "archival"
|
|
58
|
+
action :unarchive!, method: :delete, path: "archival"
|
|
59
|
+
action :activate!, method: :patch, path: "activation"
|
|
60
|
+
action :deactivate!, method: :patch, path: "deactivation"
|
|
61
|
+
action :publish!, method: :post, path: "publication"
|
|
62
|
+
action :unpublish!, method: :delete, path: "publication"
|
|
63
|
+
action :duplicate, method: :post, path: "duplication"
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Tito
|
|
2
|
+
module Admin
|
|
3
|
+
module Resources
|
|
4
|
+
class ReleaseInvitation < Tito::Resource
|
|
5
|
+
event_scoped!
|
|
6
|
+
path_template "%{account}/%{event}/rsvp_lists/%{parent_id}/release_invitations"
|
|
7
|
+
resource_name "release_invitation"
|
|
8
|
+
collection_name "release_invitations"
|
|
9
|
+
supports :list, :show, :create, :update, :delete
|
|
10
|
+
|
|
11
|
+
attribute :id, :integer
|
|
12
|
+
attribute :slug, :string
|
|
13
|
+
attribute :email, :string
|
|
14
|
+
attribute :first_name, :string
|
|
15
|
+
attribute :last_name, :string
|
|
16
|
+
attribute :name, :string
|
|
17
|
+
attribute :status, :string
|
|
18
|
+
attribute :redeemed, :boolean
|
|
19
|
+
attribute :auto, :boolean
|
|
20
|
+
attribute :guest, :boolean
|
|
21
|
+
attribute :discount_code, :string
|
|
22
|
+
attribute :expires_at, :datetime
|
|
23
|
+
attribute :unique_url, :string
|
|
24
|
+
attribute :redirect, :string
|
|
25
|
+
attribute :created_at, :datetime
|
|
26
|
+
attribute :updated_at, :datetime
|
|
27
|
+
|
|
28
|
+
expandable :registration
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module Tito
|
|
2
|
+
module Admin
|
|
3
|
+
module Resources
|
|
4
|
+
class RsvpList < Tito::Resource
|
|
5
|
+
event_scoped!
|
|
6
|
+
path_template "%{account}/%{event}/rsvp_lists"
|
|
7
|
+
resource_name "rsvp_list"
|
|
8
|
+
collection_name "rsvp_lists"
|
|
9
|
+
supports :list, :show, :create, :update, :delete
|
|
10
|
+
|
|
11
|
+
attribute :id, :integer
|
|
12
|
+
attribute :slug, :string
|
|
13
|
+
attribute :title, :string
|
|
14
|
+
attribute :redeemed_count, :integer
|
|
15
|
+
attribute :nos_count, :integer
|
|
16
|
+
attribute :maybes_count, :integer
|
|
17
|
+
attribute :release_invitations_count, :integer
|
|
18
|
+
attribute :message_slug, :string
|
|
19
|
+
attribute :created_at, :datetime
|
|
20
|
+
attribute :updated_at, :datetime
|
|
21
|
+
|
|
22
|
+
has_many :release_invitations, resource_class_name: "ReleaseInvitation"
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
module Tito
|
|
2
|
+
module Admin
|
|
3
|
+
module Resources
|
|
4
|
+
class Ticket < Tito::Resource
|
|
5
|
+
event_scoped!
|
|
6
|
+
path_template "%{account}/%{event}/tickets"
|
|
7
|
+
resource_name "ticket"
|
|
8
|
+
collection_name "tickets"
|
|
9
|
+
supports :list, :show, :create, :update
|
|
10
|
+
|
|
11
|
+
attribute :id, :integer
|
|
12
|
+
attribute :slug, :string
|
|
13
|
+
attribute :reference, :string
|
|
14
|
+
attribute :number, :integer
|
|
15
|
+
attribute :email, :string
|
|
16
|
+
attribute :first_name, :string
|
|
17
|
+
attribute :last_name, :string
|
|
18
|
+
attribute :name, :string
|
|
19
|
+
attribute :company_name, :string
|
|
20
|
+
attribute :job_title, :string
|
|
21
|
+
attribute :phone_number, :string
|
|
22
|
+
attribute :state, :string
|
|
23
|
+
attribute :price, :decimal
|
|
24
|
+
attribute :price_less_tax, :decimal
|
|
25
|
+
attribute :total_paid, :decimal
|
|
26
|
+
attribute :total_paid_less_tax, :decimal
|
|
27
|
+
attribute :total_tax_paid, :decimal
|
|
28
|
+
attribute :release_id, :integer
|
|
29
|
+
attribute :release_archived, :boolean
|
|
30
|
+
attribute :registration_id, :integer
|
|
31
|
+
attribute :discount_code_used, :string
|
|
32
|
+
attribute :tag_names, :string_array
|
|
33
|
+
attribute :test_mode, :boolean
|
|
34
|
+
attribute :assigned, :boolean
|
|
35
|
+
attribute :unique_url, :string
|
|
36
|
+
attribute :avatar_url, :string
|
|
37
|
+
attribute :qr_url, :string
|
|
38
|
+
attribute :qr_code_disabled, :boolean
|
|
39
|
+
attribute :show_qr_code, :boolean
|
|
40
|
+
attribute :vcard_url, :string
|
|
41
|
+
attribute :vcard_data, :string
|
|
42
|
+
attribute :changes_locked, :boolean
|
|
43
|
+
attribute :lock_changes, :boolean
|
|
44
|
+
attribute :tags, :string
|
|
45
|
+
attribute :event, :string
|
|
46
|
+
attribute :void, :boolean
|
|
47
|
+
attribute :metadata, :json
|
|
48
|
+
attribute :consented_at, :datetime
|
|
49
|
+
attribute :created_at, :datetime
|
|
50
|
+
attribute :updated_at, :datetime
|
|
51
|
+
|
|
52
|
+
expandable :activities, :answers, :opt_ins, :registration, :release, :responses, :upgrade_ids
|
|
53
|
+
|
|
54
|
+
action :void!, method: :post, path: "void"
|
|
55
|
+
action :reassign!, method: :post, path: "reassignments"
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Tito
|
|
2
|
+
module Admin
|
|
3
|
+
module Resources
|
|
4
|
+
class Venue < Tito::Resource
|
|
5
|
+
event_scoped!
|
|
6
|
+
path_template "%{account}/%{event}/venues"
|
|
7
|
+
resource_name "venue"
|
|
8
|
+
collection_name "venues"
|
|
9
|
+
supports :list, :show, :create, :update, :delete
|
|
10
|
+
|
|
11
|
+
attribute :id, :integer
|
|
12
|
+
attribute :name, :string
|
|
13
|
+
attribute :address, :string
|
|
14
|
+
attribute :created_at, :datetime
|
|
15
|
+
attribute :updated_at, :datetime
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Tito
|
|
2
|
+
module Admin
|
|
3
|
+
module Resources
|
|
4
|
+
class WaitlistedPerson < Tito::Resource
|
|
5
|
+
event_scoped!
|
|
6
|
+
path_template "%{account}/%{event}/waitlisted_people"
|
|
7
|
+
resource_name "waitlisted_person"
|
|
8
|
+
collection_name "waitlisted_people"
|
|
9
|
+
supports :list, :show, :create, :update, :delete
|
|
10
|
+
|
|
11
|
+
attribute :id, :integer
|
|
12
|
+
attribute :release_id, :integer
|
|
13
|
+
attribute :name, :string
|
|
14
|
+
attribute :email, :string
|
|
15
|
+
attribute :state, :string
|
|
16
|
+
attribute :status, :string
|
|
17
|
+
attribute :offered_at, :datetime
|
|
18
|
+
attribute :offered, :boolean
|
|
19
|
+
attribute :expires_at, :datetime
|
|
20
|
+
attribute :expired, :boolean
|
|
21
|
+
attribute :unique_offer_url, :string
|
|
22
|
+
attribute :joined_at, :datetime
|
|
23
|
+
attribute :joined, :boolean
|
|
24
|
+
attribute :redeemed_at, :datetime
|
|
25
|
+
attribute :redeemed, :boolean
|
|
26
|
+
attribute :rejected, :boolean
|
|
27
|
+
attribute :message, :string
|
|
28
|
+
attribute :created_at, :datetime
|
|
29
|
+
attribute :updated_at, :datetime
|
|
30
|
+
|
|
31
|
+
expandable :registration, :release
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Tito
|
|
2
|
+
module Admin
|
|
3
|
+
module Resources
|
|
4
|
+
class WebhookEndpoint < Tito::Resource
|
|
5
|
+
account_scoped!
|
|
6
|
+
path_template "webhook_endpoints"
|
|
7
|
+
resource_name "webhook_endpoint"
|
|
8
|
+
collection_name "webhook_endpoints"
|
|
9
|
+
supports :list, :show, :create, :update, :delete
|
|
10
|
+
|
|
11
|
+
attribute :id, :integer
|
|
12
|
+
attribute :url, :string
|
|
13
|
+
attribute :included_triggers, :string_array
|
|
14
|
+
attribute :deprecated, :boolean
|
|
15
|
+
attribute :created_at, :datetime
|
|
16
|
+
attribute :updated_at, :datetime
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
module Tito
|
|
2
|
+
module Admin
|
|
3
|
+
class Scope
|
|
4
|
+
attr_reader :client, :account, :event, :resource_class, :parent_id
|
|
5
|
+
|
|
6
|
+
def initialize(client:, account:, event: nil, resource_class:, parent_id: nil)
|
|
7
|
+
@client = client
|
|
8
|
+
@account = account
|
|
9
|
+
@event = event
|
|
10
|
+
@resource_class = resource_class
|
|
11
|
+
@parent_id = parent_id
|
|
12
|
+
validate!
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def connection
|
|
16
|
+
client.connection
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def collection_path(suffix: nil)
|
|
20
|
+
base = interpolate(resource_class.path_template)
|
|
21
|
+
suffix ? "#{base}#{suffix}" : base
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def member_path(id_or_slug)
|
|
25
|
+
if resource_class.member_path_template
|
|
26
|
+
interpolate(resource_class.member_path_template, id_or_slug: id_or_slug)
|
|
27
|
+
else
|
|
28
|
+
"#{collection_path}/#{id_or_slug}"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def nested_scope(child_class, parent_id:)
|
|
33
|
+
self.class.new(
|
|
34
|
+
client: client,
|
|
35
|
+
account: account,
|
|
36
|
+
event: event,
|
|
37
|
+
resource_class: child_class,
|
|
38
|
+
parent_id: parent_id
|
|
39
|
+
)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def request(method, path, params: {}, body: {})
|
|
43
|
+
case method
|
|
44
|
+
when :get then connection.get(path, params: params)
|
|
45
|
+
when :post then connection.post(path, body: body)
|
|
46
|
+
when :patch then connection.patch(path, body: body)
|
|
47
|
+
when :delete then connection.delete(path)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
def interpolate(template, id_or_slug: nil)
|
|
54
|
+
result = template.dup
|
|
55
|
+
result.gsub!("%{account}", account.to_s)
|
|
56
|
+
result.gsub!("%{event}", event.to_s) if event
|
|
57
|
+
result.gsub!("%{parent_id}", parent_id.to_s) if parent_id
|
|
58
|
+
result.gsub!("%{id_or_slug}", id_or_slug.to_s) if id_or_slug
|
|
59
|
+
result
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def validate!
|
|
63
|
+
raise Tito::Errors::ConfigurationError, "account is required" unless account
|
|
64
|
+
if resource_class.event_scoped? && event.nil?
|
|
65
|
+
raise Tito::Errors::ConfigurationError,
|
|
66
|
+
"event is required for #{resource_class.resource_name} resources"
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module Tito
|
|
2
|
+
class Connection
|
|
3
|
+
attr_reader :base_url
|
|
4
|
+
|
|
5
|
+
def initialize(token:, base_url: nil)
|
|
6
|
+
@token = token
|
|
7
|
+
@base_url = base_url || Tito.configuration.base_url
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def get(path, params: {})
|
|
11
|
+
handle_response faraday.get(path, params)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def post(path, body: {})
|
|
15
|
+
handle_response faraday.post(path, body)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def patch(path, body: {})
|
|
19
|
+
handle_response faraday.patch(path, body)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def delete(path)
|
|
23
|
+
handle_response faraday.delete(path)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def faraday
|
|
27
|
+
@faraday ||= Faraday.new(url: @base_url) do |f|
|
|
28
|
+
f.headers["Authorization"] = "Token token=#{@token}"
|
|
29
|
+
f.headers["Accept"] = "application/json"
|
|
30
|
+
f.request :json
|
|
31
|
+
f.response :json, content_type: /\bjson$/
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def handle_response(response)
|
|
38
|
+
return response.body if response.success?
|
|
39
|
+
raise Tito::Errors.from_response(response)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
data/lib/tito/errors.rb
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module Tito
|
|
2
|
+
module Errors
|
|
3
|
+
class Error < StandardError; end
|
|
4
|
+
class ConfigurationError < Error; end
|
|
5
|
+
|
|
6
|
+
class ApiError < Error
|
|
7
|
+
attr_reader :status, :body, :errors
|
|
8
|
+
|
|
9
|
+
def initialize(message = nil, status: nil, body: nil)
|
|
10
|
+
@status = status
|
|
11
|
+
@body = body
|
|
12
|
+
@errors = body.is_a?(Hash) ? (body["errors"] || {}) : {}
|
|
13
|
+
super(message || (body.is_a?(Hash) && body["message"]) || "API error (#{status})")
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class UnauthorizedError < ApiError; end # 401
|
|
18
|
+
class ForbiddenError < ApiError; end # 403
|
|
19
|
+
class NotFoundError < ApiError; end # 404
|
|
20
|
+
class ValidationError < ApiError; end # 422
|
|
21
|
+
class RateLimitError < ApiError; end # 429
|
|
22
|
+
class ServerError < ApiError; end # 5xx
|
|
23
|
+
|
|
24
|
+
MAPPING = {
|
|
25
|
+
401 => UnauthorizedError,
|
|
26
|
+
403 => ForbiddenError,
|
|
27
|
+
404 => NotFoundError,
|
|
28
|
+
422 => ValidationError,
|
|
29
|
+
429 => RateLimitError
|
|
30
|
+
}.freeze
|
|
31
|
+
|
|
32
|
+
def self.from_response(response)
|
|
33
|
+
status = response.status
|
|
34
|
+
body = response.body
|
|
35
|
+
|
|
36
|
+
klass = MAPPING[status] || (status >= 500 ? ServerError : ApiError)
|
|
37
|
+
klass.new(status: status, body: body)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|