turba_kit 0.0.8 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/Gemfile +0 -7
- data/lib/turba_kit.rb +117 -18
- data/lib/turba_kit/availability.rb +7 -0
- data/lib/turba_kit/call_to_action.rb +25 -0
- data/lib/turba_kit/checkins.rb +30 -0
- data/lib/turba_kit/content.rb +25 -0
- data/lib/turba_kit/countries.rb +11 -0
- data/lib/turba_kit/crowd_table.rb +37 -0
- data/lib/turba_kit/error.rb +15 -169
- data/lib/turba_kit/link.rb +25 -0
- data/lib/turba_kit/misc.rb +25 -0
- data/lib/turba_kit/notification.rb +25 -0
- data/lib/turba_kit/phonenumber.rb +25 -0
- data/lib/turba_kit/place.rb +25 -0
- data/lib/turba_kit/services.rb +39 -0
- data/lib/turba_kit/tip.rb +25 -0
- data/lib/turba_kit/units.rb +36 -0
- data/lib/turba_kit/version.rb +1 -1
- data/spec/cassettes/availability.json +1 -0
- data/spec/cassettes/checkins.json +1 -0
- data/spec/cassettes/countries.json +1 -0
- data/spec/cassettes/country_fr_.json +1 -0
- data/spec/cassettes/create_checkins.json +1 -0
- data/spec/cassettes/create_service_content.json +1 -0
- data/spec/cassettes/create_service_link.json +1 -0
- data/spec/cassettes/create_service_notification.json +1 -0
- data/spec/cassettes/create_service_phonenumber.json +1 -0
- data/spec/cassettes/create_service_place.json +1 -0
- data/spec/cassettes/create_service_tip.json +1 -0
- data/spec/cassettes/search_service.json +1 -0
- data/spec/cassettes/service.json +1 -0
- data/spec/cassettes/service_crowd_table.json +1 -0
- data/spec/cassettes/update_service_content.json +1 -0
- data/spec/cassettes/update_service_crowd_table.json +1 -0
- data/spec/cassettes/update_service_link.json +1 -0
- data/spec/cassettes/update_service_phonenumber.json +1 -0
- data/spec/cassettes/update_service_place.json +1 -0
- data/spec/cassettes/update_service_tip.json +1 -0
- data/spec/lib/availability_spec.rb +15 -0
- data/spec/lib/checkins_spec.rb +22 -0
- data/spec/lib/content_spec.rb +31 -0
- data/spec/lib/countries_spec.rb +12 -14
- data/spec/lib/crowd_table_spec.rb +24 -0
- data/spec/lib/link_spec.rb +30 -0
- data/spec/lib/notification_spec.rb +17 -0
- data/spec/lib/phonenumber_spec.rb +28 -0
- data/spec/lib/place_spec.rb +23 -36
- data/spec/lib/services_spec.rb +11 -53
- data/spec/lib/tip_spec.rb +30 -0
- data/spec/spec_helper.rb +0 -4
- data/turba_kit.gemspec +5 -2
- metadata +115 -269
- data/lib/turba_kit/arguments.rb +0 -14
- data/lib/turba_kit/authentication.rb +0 -10
- data/lib/turba_kit/client.rb +0 -168
- data/lib/turba_kit/client/categories.rb +0 -41
- data/lib/turba_kit/client/checkins.rb +0 -14
- data/lib/turba_kit/client/comments.rb +0 -9
- data/lib/turba_kit/client/contents.rb +0 -26
- data/lib/turba_kit/client/countries.rb +0 -14
- data/lib/turba_kit/client/crowd_table.rb +0 -25
- data/lib/turba_kit/client/links.rb +0 -26
- data/lib/turba_kit/client/migrations.rb +0 -15
- data/lib/turba_kit/client/notifications.rb +0 -26
- data/lib/turba_kit/client/organismes.rb +0 -41
- data/lib/turba_kit/client/phonenumbers.rb +0 -26
- data/lib/turba_kit/client/places.rb +0 -26
- data/lib/turba_kit/client/search.rb +0 -9
- data/lib/turba_kit/client/services.rb +0 -41
- data/lib/turba_kit/client/tips.rb +0 -26
- data/lib/turba_kit/configurable.rb +0 -74
- data/lib/turba_kit/default.rb +0 -102
- data/lib/turba_kit/response/raise_error.rb +0 -20
- data/spec/cassettes/TurbaKit_Client_Categories/_categories/handles_the_country_code_option.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Categories/_category/returns_a_category.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Categories/_create_category/creates_a_category.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Categories/_delete_category/deletes_a_category_and_returns_true.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Categories/_delete_category/returns_false_if_category_doesn_t_exist.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Categories/_update_category/updates_a_category.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Contents/_create_content/creates_a_content.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Contents/_delete_content/deletes_a_content.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Contents/_service_content/returns_a_content.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Contents/_service_contents/lists_contents.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Contents/_update_content/updates_a_content.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Countries/_countries/returns_all_countries.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Countries/_country/returns_a_country.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Crowds/_create_crowd/creates_a_crowd.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Crowds/_delete_crowd/deletes_a_crowd.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Crowds/_service_crowd/returns_a_crowd.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Crowds/_service_crowds/lists_crowds.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Crowds/_update_crowd/updates_a_crowd.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Links/_create_link/creates_a_link.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Links/_delete_link/deletes_a_link.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Links/_service_link/returns_a_link.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Links/_service_links/lists_links.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Links/_update_link/updates_a_link.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Notifications/_create_notification/creates_a_notification.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Notifications/_delete_notification/deletes_a_notification.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Notifications/_service_notification/returns_a_notification.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Notifications/_service_notifications/lists_notifications.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Notifications/_update_notification/updates_a_notification.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Organismes/_create_organisme/creates_an_organisme.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Organismes/_delete_organisme/deletes_a_organisme_and_returns_true.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Organismes/_delete_organisme/returns_false_if_organisme_doesn_t_exist.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Organismes/_organisme/returns_a_organisme.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Organismes/_organismes/handles_the_country_code_option.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Organismes/_update_organisme/updates_an_organisme.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Phonenumbers/_create_phonenumber/creates_a_phonenumber.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Phonenumbers/_delete_phonenumber/deletes_a_phonenumber.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Phonenumbers/_service_phonenumber/returns_a_phonenumber.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Phonenumbers/_service_phonenumbers/lists_phonenumbers.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Phonenumbers/_update_phonenumber/updates_a_phonenumber.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Places/_create_place/creates_a_place.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Places/_delete_place/deletes_a_place.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Places/_service_place/returns_a_place.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Places/_service_places/lists_places.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Places/_update_place/updates_a_place.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Services/_service/returns_a_service.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Services/_services/handles_the_country_code_option.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Tips/_create_tip/creates_a_tip.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Tips/_delete_tip/deletes_a_tip.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Tips/_service_tip/returns_a_tip.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Tips/_service_tips/lists_tips.json +0 -1
- data/spec/cassettes/TurbaKit_Client_Tips/_update_tip/updates_a_tip.json +0 -1
- data/spec/cassettes/Turkit_Client_Categories/_categories/handles_the_country_code_option.json +0 -1
- data/spec/cassettes/Turkit_Client_Categories/_categories/returns_all_categories.json +0 -1
- data/spec/cassettes/Turkit_Client_Categories/_category/returns_a_category.json +0 -1
- data/spec/cassettes/Turkit_Client_Categories/_create_category/creates_a_category.json +0 -1
- data/spec/cassettes/Turkit_Client_Categories/_delete_category/deletes_a_category_and_returns_true.json +0 -1
- data/spec/cassettes/Turkit_Client_Categories/_delete_category/returns_false_if_category_doesn_t_exist.json +0 -1
- data/spec/cassettes/Turkit_Client_Categories/_search_category/returns_a_list_of_categories.json +0 -1
- data/spec/cassettes/Turkit_Client_Categories/_update_category/updates_a_category.json +0 -1
- data/spec/cassettes/Turkit_Client_Contents/_create_content/creates_a_content.json +0 -1
- data/spec/cassettes/Turkit_Client_Contents/_delete_content/deletes_a_content.json +0 -1
- data/spec/cassettes/Turkit_Client_Contents/_service_content/returns_a_content.json +0 -1
- data/spec/cassettes/Turkit_Client_Contents/_service_contents/lists_contents.json +0 -1
- data/spec/cassettes/Turkit_Client_Contents/_update_content/updates_a_content.json +0 -1
- data/spec/cassettes/Turkit_Client_Countries/_countries/returns_all_countries.json +0 -1
- data/spec/cassettes/Turkit_Client_Countries/_country/returns_a_country.json +0 -1
- data/spec/cassettes/Turkit_Client_Crowds/_create_crowd/creates_a_crowd.json +0 -1
- data/spec/cassettes/Turkit_Client_Crowds/_delete_crowd/deletes_a_crowd.json +0 -1
- data/spec/cassettes/Turkit_Client_Crowds/_service_crowd/returns_a_crowd.json +0 -1
- data/spec/cassettes/Turkit_Client_Crowds/_service_crowds/lists_crowds.json +0 -1
- data/spec/cassettes/Turkit_Client_Crowds/_update_crowd/updates_a_crowd.json +0 -1
- data/spec/cassettes/Turkit_Client_Links/_create_link/creates_a_link.json +0 -1
- data/spec/cassettes/Turkit_Client_Links/_delete_link/deletes_a_link.json +0 -1
- data/spec/cassettes/Turkit_Client_Links/_service_link/returns_a_link.json +0 -1
- data/spec/cassettes/Turkit_Client_Links/_service_links/lists_links.json +0 -1
- data/spec/cassettes/Turkit_Client_Links/_update_link/updates_a_link.json +0 -1
- data/spec/cassettes/Turkit_Client_Notifications/_create_notification/creates_a_notification.json +0 -1
- data/spec/cassettes/Turkit_Client_Notifications/_delete_notification/deletes_a_notification.json +0 -1
- data/spec/cassettes/Turkit_Client_Notifications/_service_notification/returns_a_notification.json +0 -1
- data/spec/cassettes/Turkit_Client_Notifications/_service_notifications/lists_notifications.json +0 -1
- data/spec/cassettes/Turkit_Client_Notifications/_update_notification/updates_a_notification.json +0 -1
- data/spec/cassettes/Turkit_Client_Organismes/_create_organisme/creates_an_organisme.json +0 -1
- data/spec/cassettes/Turkit_Client_Organismes/_delete_organisme/deletes_a_organisme_and_returns_true.json +0 -1
- data/spec/cassettes/Turkit_Client_Organismes/_delete_organisme/returns_false_if_organisme_doesn_t_exist.json +0 -1
- data/spec/cassettes/Turkit_Client_Organismes/_organisme/returns_a_organisme.json +0 -1
- data/spec/cassettes/Turkit_Client_Organismes/_organismes/handles_the_country_code_option.json +0 -1
- data/spec/cassettes/Turkit_Client_Organismes/_organismes/returns_all_organismes.json +0 -1
- data/spec/cassettes/Turkit_Client_Organismes/_search_organisme/returns_a_list_of_organismes.json +0 -1
- data/spec/cassettes/Turkit_Client_Organismes/_update_organisme/updates_an_organisme.json +0 -1
- data/spec/cassettes/Turkit_Client_Phonenumbers/_create_phonenumber/creates_a_phonenumber.json +0 -1
- data/spec/cassettes/Turkit_Client_Phonenumbers/_delete_phonenumber/deletes_a_phonenumber.json +0 -1
- data/spec/cassettes/Turkit_Client_Phonenumbers/_service_phonenumber/returns_a_phonenumber.json +0 -1
- data/spec/cassettes/Turkit_Client_Phonenumbers/_service_phonenumbers/lists_phonenumbers.json +0 -1
- data/spec/cassettes/Turkit_Client_Phonenumbers/_update_phonenumber/updates_a_phonenumber.json +0 -1
- data/spec/cassettes/Turkit_Client_Places/_create_place/creates_a_place.json +0 -1
- data/spec/cassettes/Turkit_Client_Places/_delete_place/deletes_a_place.json +0 -1
- data/spec/cassettes/Turkit_Client_Places/_service_place/returns_a_place.json +0 -1
- data/spec/cassettes/Turkit_Client_Places/_service_places/lists_places.json +0 -1
- data/spec/cassettes/Turkit_Client_Places/_update_place/updates_a_place.json +0 -1
- data/spec/cassettes/Turkit_Client_Services/_search_service/returns_a_list_of_services.json +0 -1
- data/spec/cassettes/Turkit_Client_Services/_service/returns_a_service.json +0 -1
- data/spec/cassettes/Turkit_Client_Services/_services/handles_the_country_code_option.json +0 -1
- data/spec/cassettes/Turkit_Client_Services/_services/returns_all_services.json +0 -1
- data/spec/cassettes/Turkit_Client_Tips/_create_tip/creates_a_tip.json +0 -1
- data/spec/cassettes/Turkit_Client_Tips/_delete_tip/deletes_a_tip.json +0 -1
- data/spec/cassettes/Turkit_Client_Tips/_service_tip/returns_a_tip.json +0 -1
- data/spec/cassettes/Turkit_Client_Tips/_service_tips/lists_tips.json +0 -1
- data/spec/cassettes/Turkit_Client_Tips/_update_tip/updates_a_tip.json +0 -1
- data/spec/lib/categories_spec.rb +0 -64
- data/spec/lib/contents_spec.rb +0 -47
- data/spec/lib/crowds_spec.rb +0 -47
- data/spec/lib/links_spec.rb +0 -47
- data/spec/lib/notifications_spec.rb +0 -47
- data/spec/lib/organismes_spec.rb +0 -64
- data/spec/lib/phonenumbers_spec.rb +0 -47
- data/spec/lib/tips_spec.rb +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5209bf98ef2ab1dd6e3f084de4d71f26ef9d12d
|
4
|
+
data.tar.gz: f598ddb1f93ed74eb97ac1c0fb162c2a77d3abc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9781057e03f8b80e756188bdcc132384bd73a0ce20f940018c9e1dc017ef46008122d38623bf427895dc9ee0e48f30b3f1078f689e391af954a5246ec373dab5
|
7
|
+
data.tar.gz: 4cfc61901cd6dff83d5e890e1338479c3cbdf4c8179fd3db16d429998880f2f1945fb6692379eaad1eada6e4bcc8cb3096d795a79fbd257c666c76e010264fc8
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.2
|
data/Gemfile
CHANGED
data/lib/turba_kit.rb
CHANGED
@@ -1,27 +1,126 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
1
|
+
require 'oj'
|
2
|
+
require 'typhoeus'
|
3
|
+
require 'recursive-open-struct'
|
4
|
+
require 'turba_kit/error'
|
5
|
+
require 'turba_kit/countries'
|
6
|
+
require 'turba_kit/checkins'
|
7
|
+
require 'turba_kit/availability'
|
8
|
+
require 'turba_kit/units'
|
9
|
+
require 'turba_kit/services'
|
10
|
+
require 'turba_kit/crowd_table'
|
11
|
+
require 'turba_kit/link'
|
12
|
+
require 'turba_kit/misc'
|
13
|
+
require 'turba_kit/call_to_action'
|
14
|
+
require 'turba_kit/phonenumber'
|
15
|
+
require 'turba_kit/tip'
|
16
|
+
require 'turba_kit/content'
|
17
|
+
require 'turba_kit/place'
|
18
|
+
require 'turba_kit/notification'
|
19
|
+
require 'active_support/core_ext/hash'
|
3
20
|
|
4
|
-
# Ruby toolkit for the Turba API
|
5
21
|
module TurbaKit
|
6
|
-
class
|
7
|
-
include TurbaKit::
|
8
|
-
|
9
|
-
|
10
|
-
|
22
|
+
class Client
|
23
|
+
include TurbaKit::Countries
|
24
|
+
include TurbaKit::Checkins
|
25
|
+
include TurbaKit::Availability
|
26
|
+
include TurbaKit::Units
|
27
|
+
include TurbaKit::Services
|
28
|
+
include TurbaKit::CrowdTable
|
29
|
+
include TurbaKit::Link
|
30
|
+
include TurbaKit::Misc
|
31
|
+
include TurbaKit::CallToAction
|
32
|
+
include TurbaKit::Phonenumber
|
33
|
+
include TurbaKit::Tip
|
34
|
+
include TurbaKit::Content
|
35
|
+
include TurbaKit::Place
|
36
|
+
include TurbaKit::Notification
|
37
|
+
|
38
|
+
def initialize(api_key, options = {})
|
39
|
+
@api_key = api_key
|
40
|
+
default_options = {
|
41
|
+
version: '/v2',
|
42
|
+
domain: 'api.turba-webservices.com',
|
43
|
+
scheme: 'https'
|
44
|
+
}
|
45
|
+
@options = default_options.merge(options)
|
46
|
+
end
|
47
|
+
|
48
|
+
def api_url
|
49
|
+
@api_url ||= "#{@options[:scheme]}://#{@options[:domain]}#{@options[:version]}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def default_params
|
53
|
+
@default_params ||= { api_key: @api_key }
|
54
|
+
end
|
55
|
+
|
56
|
+
def put_request(endpoint, options = {})
|
57
|
+
options[:namespace] ||= nil
|
58
|
+
options[:accept] ||= "application/json"
|
59
|
+
options[:params] ||= {}
|
60
|
+
|
61
|
+
request = Typhoeus::Request.new(
|
62
|
+
"#{api_url}#{endpoint}",
|
63
|
+
method: :put,
|
64
|
+
params: default_params,
|
65
|
+
body: Oj.dump(options[:params], mode: :compat),
|
66
|
+
headers: { "Content-Type" => options[:accept] }
|
67
|
+
).run
|
68
|
+
response(request, options[:namespace])
|
69
|
+
end
|
70
|
+
|
71
|
+
def post_request(endpoint, options = {})
|
72
|
+
options[:namespace] ||= nil
|
73
|
+
options[:accept] ||= "application/json"
|
74
|
+
options[:params] ||= {}
|
75
|
+
|
76
|
+
request = Typhoeus::Request.new(
|
77
|
+
"#{api_url}#{endpoint}",
|
78
|
+
method: :post,
|
79
|
+
params: default_params,
|
80
|
+
body: Oj.dump(options[:params], mode: :compat),
|
81
|
+
headers: { "Content-Type" => options[:accept] }
|
82
|
+
).run
|
83
|
+
response(request, options[:namespace])
|
84
|
+
end
|
85
|
+
|
86
|
+
def delete_request(endpoint)
|
87
|
+
request = Typhoeus::Request.new(
|
88
|
+
"#{api_url}#{endpoint}",
|
89
|
+
method: :delete,
|
90
|
+
params: default_params,
|
91
|
+
).run
|
92
|
+
|
93
|
+
response(request, nil)
|
94
|
+
end
|
95
|
+
|
96
|
+
def get_request(endpoint, options = {})
|
97
|
+
options[:namespace] ||= nil
|
98
|
+
options[:accept] ||= "application/json"
|
99
|
+
options[:params] ||= {}
|
100
|
+
|
101
|
+
request = Typhoeus::Request.new(
|
102
|
+
"#{api_url}#{endpoint}",
|
103
|
+
method: :get,
|
104
|
+
params: default_params.merge(options[:params]),
|
105
|
+
headers: { Accept: options[:accept] }
|
106
|
+
).run
|
107
|
+
|
108
|
+
response(request, options[:namespace])
|
11
109
|
end
|
12
110
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
111
|
+
def response(request, namespace)
|
112
|
+
body = Oj.load(request.body)
|
113
|
+
body = body.with_indifferent_access unless body.nil?
|
114
|
+
status = request.options[:response_code]
|
115
|
+
body ||= request.body
|
17
116
|
|
18
|
-
|
117
|
+
if (400..599).include?(status)
|
118
|
+
return Error.from_response(body, status)
|
119
|
+
end
|
19
120
|
|
20
|
-
|
21
|
-
|
22
|
-
|
121
|
+
return "" if body.empty?
|
122
|
+
|
123
|
+
namespace ? RecursiveOpenStruct.new(body[namespace], recurse_over_arrays: true) : RecursiveOpenStruct.new(body, recurse_over_arrays: true)
|
23
124
|
end
|
24
125
|
end
|
25
126
|
end
|
26
|
-
|
27
|
-
TurbaKit.setup
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module TurbaKit
|
2
|
+
module CallToAction
|
3
|
+
def update_service_call_to_action(service_id, call_to_action_id, options = {})
|
4
|
+
put_request("/services/#{service_id}/call_to_actions/#{call_to_action_id}", {
|
5
|
+
namespace: :call_to_action,
|
6
|
+
params: {
|
7
|
+
call_to_action: options
|
8
|
+
}
|
9
|
+
})
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_service_call_to_action(service_id, options = {})
|
13
|
+
post_request("/services/#{service_id}/call_to_actions", {
|
14
|
+
namespace: :call_to_action,
|
15
|
+
params: {
|
16
|
+
call_to_action: options
|
17
|
+
}
|
18
|
+
})
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete_service_call_to_action(service_id, call_to_action_id, options = {})
|
22
|
+
delete_request("/services/#{service_id}/call_to_actions/#{call_to_action_id}")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module TurbaKit
|
2
|
+
module Checkins
|
3
|
+
def checkins(options = {})
|
4
|
+
default = {
|
5
|
+
page: 0,
|
6
|
+
per_page: 10,
|
7
|
+
published: true,
|
8
|
+
country_code: 'FR',
|
9
|
+
type: 'parent'
|
10
|
+
}
|
11
|
+
|
12
|
+
get_request("/checkins", {params: default.merge(options)})
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_checkin(service_id, wait, options = {})
|
16
|
+
default = {
|
17
|
+
user: :guest,
|
18
|
+
location: 'N/A',
|
19
|
+
platform: :web,
|
20
|
+
service_id: service_id,
|
21
|
+
wait: wait
|
22
|
+
}
|
23
|
+
post_request("/checkins", {
|
24
|
+
params: {
|
25
|
+
checkin: default.merge(options)
|
26
|
+
}
|
27
|
+
})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module TurbaKit
|
2
|
+
module Content
|
3
|
+
def update_service_content(service_id, content_id, options = {})
|
4
|
+
put_request("/services/#{service_id}/contents/#{content_id}", {
|
5
|
+
namespace: :content,
|
6
|
+
params: {
|
7
|
+
content: options
|
8
|
+
}
|
9
|
+
})
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_service_content(service_id, options = {})
|
13
|
+
post_request("/services/#{service_id}/contents", {
|
14
|
+
namespace: :content,
|
15
|
+
params: {
|
16
|
+
content: options
|
17
|
+
}
|
18
|
+
})
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete_service_content(service_id, content_id, options = {})
|
22
|
+
delete_request("/services/#{service_id}/contents/#{content_id}")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module TurbaKit
|
2
|
+
module CrowdTable
|
3
|
+
def service_crowd_table(service_id, options = {})
|
4
|
+
default = {
|
5
|
+
from: Time.now.beginning_of_day.to_datetime.new_offset(0).to_i,
|
6
|
+
to: (Time.now + 6.days).beginning_of_day.to_datetime.new_offset(0).to_i
|
7
|
+
}
|
8
|
+
|
9
|
+
get_request("/services/#{service_id}/crowd_table", {
|
10
|
+
namespace: :crowd_table,
|
11
|
+
params: default.merge(options)
|
12
|
+
})
|
13
|
+
end
|
14
|
+
|
15
|
+
def update_service_crowd_table(service_id, crowd_table_id, options = {})
|
16
|
+
put_request("/services/#{service_id}/crowd_tables/#{crowd_table_id}", {
|
17
|
+
namespace: :crowd_table,
|
18
|
+
params: {
|
19
|
+
crowd_table: options
|
20
|
+
}
|
21
|
+
})
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_service_crowd_table(service_id, options = {})
|
25
|
+
post_request("/services/#{service_id}/crowd_table", {
|
26
|
+
namespace: :crowd_table,
|
27
|
+
params: {
|
28
|
+
crowd_table: options
|
29
|
+
}
|
30
|
+
})
|
31
|
+
end
|
32
|
+
|
33
|
+
def delete_service_crowd_table(service_id, options = {})
|
34
|
+
delete_request("/services/#{service_id}/crowd_table")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/turba_kit/error.rb
CHANGED
@@ -1,23 +1,12 @@
|
|
1
1
|
module TurbaKit
|
2
|
-
# Custom error class for rescuing from all Turba errors
|
3
2
|
class Error < StandardError
|
4
|
-
|
5
|
-
|
6
|
-
# Returns the appropriate TurbaKit::Error subclass based
|
7
|
-
# on status and response message
|
8
|
-
#
|
9
|
-
# @param [Hash] response HTTP response
|
10
|
-
# @return [TurbaKit::Error]
|
11
|
-
def self.from_response(response)
|
12
|
-
status = response[:status].to_i
|
13
|
-
body = response[:body].to_s
|
14
|
-
headers = response[:response_headers]
|
15
|
-
|
16
|
-
if klass = case status
|
3
|
+
def self.from_response(body, status)
|
4
|
+
if klass = case status.to_i
|
17
5
|
when 400 then TurbaKit::BadRequest
|
18
|
-
when 401 then
|
19
|
-
when 403 then
|
6
|
+
when 401 then TurbaKit::Unauthorized
|
7
|
+
when 403 then TurbaKit::Forbidden
|
20
8
|
when 404 then TurbaKit::NotFound
|
9
|
+
when 405 then TurbaKit::MethodNotAllowed
|
21
10
|
when 406 then TurbaKit::NotAcceptable
|
22
11
|
when 409 then TurbaKit::Conflict
|
23
12
|
when 415 then TurbaKit::UnsupportedMediaType
|
@@ -29,181 +18,38 @@ module TurbaKit
|
|
29
18
|
when 503 then TurbaKit::ServiceUnavailable
|
30
19
|
when 500..599 then TurbaKit::ServerError
|
31
20
|
end
|
32
|
-
klass.new(
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def initialize(response=nil)
|
37
|
-
@response = response
|
38
|
-
super(build_error_message)
|
39
|
-
@status = @response[:status]
|
40
|
-
@hash_message = build_hash_message
|
41
|
-
end
|
42
|
-
|
43
|
-
# Documentation URL returned by the API for some errors
|
44
|
-
#
|
45
|
-
# @return [String]
|
46
|
-
def documentation_url
|
47
|
-
data[:documentation_url] if data.is_a? Hash
|
48
|
-
end
|
49
|
-
|
50
|
-
# Returns most appropriate error for 401 HTTP status code
|
51
|
-
# @private
|
52
|
-
def self.error_for_401(headers)
|
53
|
-
if TurbaKit::OneTimePasswordRequired.required_header(headers)
|
54
|
-
TurbaKit::OneTimePasswordRequired
|
55
|
-
else
|
56
|
-
TurbaKit::Unauthorized
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# Returns most appropriate error for 403 HTTP status code
|
61
|
-
# @private
|
62
|
-
def self.error_for_403(body)
|
63
|
-
if body =~ /rate limit exceeded/i
|
64
|
-
TurbaKit::TooManyRequests
|
65
|
-
elsif body =~ /login attempts exceeded/i
|
66
|
-
TurbaKit::TooManyLoginAttempts
|
67
|
-
else
|
68
|
-
TurbaKit::Forbidden
|
21
|
+
klass.new(body, status)
|
69
22
|
end
|
70
23
|
end
|
71
24
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
else
|
78
|
-
[]
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
private
|
83
|
-
|
84
|
-
def data
|
85
|
-
@data ||=
|
86
|
-
if (body = @response[:body]) && !body.empty?
|
87
|
-
if body.is_a?(String) &&
|
88
|
-
@response[:response_headers] &&
|
89
|
-
@response[:response_headers][:content_type] =~ /json/
|
90
|
-
|
91
|
-
Sawyer::Agent.serializer.decode(body)
|
92
|
-
else
|
93
|
-
body
|
94
|
-
end
|
95
|
-
else
|
96
|
-
nil
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def response_message
|
101
|
-
case data
|
102
|
-
when Hash
|
103
|
-
data[:message]
|
104
|
-
when String
|
105
|
-
data
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def response_error
|
110
|
-
"Error: #{data[:error]}" if data.is_a?(Hash) && data[:error]
|
111
|
-
end
|
112
|
-
|
113
|
-
def response_error_summary
|
114
|
-
return nil unless data.is_a?(Hash) && !Array(data[:errors]).empty?
|
115
|
-
summary = "\nError summary:\n"
|
116
|
-
summary << data[:errors].map{|x| x}.join("\n")
|
117
|
-
summary
|
118
|
-
end
|
119
|
-
|
120
|
-
def build_hash_message
|
121
|
-
response = {}
|
122
|
-
return response if @response.nil?
|
123
|
-
response[:method] = @response[:method].to_s.upcase
|
124
|
-
response[:status] = @response[:status]
|
125
|
-
response[:message] = response_message unless response_message.nil?
|
126
|
-
|
127
|
-
data_array = data[:errors].map do |x|
|
128
|
-
x.is_a?(Hash) ? x[:message] : x
|
129
|
-
end unless data[:errors].blank?
|
130
|
-
|
131
|
-
response[:errors] = data_array
|
132
|
-
response[:documentation_url] = documentation_url unless documentation_url.nil?
|
133
|
-
response
|
134
|
-
end
|
135
|
-
|
136
|
-
def build_error_message
|
137
|
-
return nil if @response.nil?
|
25
|
+
def initialize(body, status)
|
26
|
+
message = {
|
27
|
+
status: status,
|
28
|
+
error: body['error']
|
29
|
+
}
|
138
30
|
|
139
|
-
message
|
140
|
-
|
141
|
-
message << "#{@response[:status]} - "
|
142
|
-
message << "#{response_message}" unless response_message.nil?
|
143
|
-
message << "#{response_error}" unless response_error.nil?
|
144
|
-
message << "#{response_error_summary}" unless response_error_summary.nil?
|
145
|
-
message << " // See: #{documentation_url}" unless documentation_url.nil?
|
146
|
-
message
|
31
|
+
super(Oj.dump(message, mode: :compat))
|
32
|
+
raise self
|
147
33
|
end
|
148
34
|
|
149
|
-
def redact_url(url_string)
|
150
|
-
%w[api_key].each do |token|
|
151
|
-
url_string.gsub!(/#{token}=\S+/, "#{token}=(redacted)") if url_string.include? token
|
152
|
-
end
|
153
|
-
url_string
|
154
|
-
end
|
155
35
|
end
|
156
36
|
|
157
37
|
# Raised on errors in the 400-499 range
|
158
38
|
class ClientError < Error; end
|
159
|
-
|
160
|
-
# Raised when Turba returns a 400 HTTP status code
|
161
39
|
class BadRequest < ClientError; end
|
162
|
-
|
163
|
-
# Raised when Turba returns a 401 HTTP status code
|
164
40
|
class Unauthorized < ClientError; end
|
165
|
-
|
166
|
-
# Raised when Turba returns a 403 HTTP status code
|
167
41
|
class Forbidden < ClientError; end
|
168
|
-
|
169
|
-
# Raised when Turba returns a 403 HTTP status code
|
170
|
-
# and body matches 'rate limit exceeded'
|
171
|
-
class TooManyRequests < Forbidden; end
|
172
|
-
|
173
|
-
# Raised when Turba returns a 403 HTTP status code
|
174
|
-
# and body matches 'login attempts exceeded'
|
175
|
-
class TooManyLoginAttempts < Forbidden; end
|
176
|
-
|
177
|
-
# Raised when Turba returns a 404 HTTP status code
|
178
42
|
class NotFound < ClientError; end
|
179
|
-
|
180
|
-
# Raised when Turba returns a 406 HTTP status code
|
43
|
+
class MethodNotAllowed < ClientError; end
|
181
44
|
class NotAcceptable < ClientError; end
|
182
|
-
|
183
|
-
# Raised when Turba returns a 409 HTTP status code
|
184
45
|
class Conflict < ClientError; end
|
185
|
-
|
186
|
-
# Raised when Turba returns a 414 HTTP status code
|
187
46
|
class UnsupportedMediaType < ClientError; end
|
188
|
-
|
189
|
-
# Raised when Turba returns a 422 HTTP status code
|
190
47
|
class UnprocessableEntity < ClientError; end
|
191
|
-
|
192
|
-
# Raised on errors in the 500-599 range
|
193
48
|
class ServerError < Error; end
|
194
|
-
|
195
|
-
# Raised when Turba returns a 500 HTTP status code
|
196
49
|
class InternalServerError < ServerError; end
|
197
|
-
|
198
|
-
# Raised when Turba returns a 501 HTTP status code
|
199
50
|
class NotImplemented < ServerError; end
|
200
|
-
|
201
|
-
# Raised when Turba returns a 502 HTTP status code
|
202
51
|
class BadGateway < ServerError; end
|
203
|
-
|
204
|
-
# Raised when Turba returns a 503 HTTP status code
|
205
52
|
class ServiceUnavailable < ServerError; end
|
206
|
-
|
207
|
-
# Raised when client fails to provide valid Content-Type
|
208
53
|
class MissingContentType < ArgumentError; end
|
54
|
+
class ApplicationCredentialsRequired < StandardError; end
|
209
55
|
end
|