turba_kit 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +15 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +1 -0
  6. data/Rakefile +22 -0
  7. data/lib/turba_kit/arguments.rb +14 -0
  8. data/lib/turba_kit/authentication.rb +10 -0
  9. data/lib/turba_kit/client/categories.rb +41 -0
  10. data/lib/turba_kit/client/checkins.rb +14 -0
  11. data/lib/turba_kit/client/comments.rb +9 -0
  12. data/lib/turba_kit/client/contents.rb +26 -0
  13. data/lib/turba_kit/client/countries.rb +14 -0
  14. data/lib/turba_kit/client/crowd_table.rb +25 -0
  15. data/lib/turba_kit/client/links.rb +26 -0
  16. data/lib/turba_kit/client/migrations.rb +15 -0
  17. data/lib/turba_kit/client/notifications.rb +26 -0
  18. data/lib/turba_kit/client/organismes.rb +41 -0
  19. data/lib/turba_kit/client/phonenumbers.rb +26 -0
  20. data/lib/turba_kit/client/places.rb +26 -0
  21. data/lib/turba_kit/client/search.rb +9 -0
  22. data/lib/turba_kit/client/services.rb +41 -0
  23. data/lib/turba_kit/client/tips.rb +26 -0
  24. data/lib/turba_kit/client.rb +168 -0
  25. data/lib/turba_kit/configurable.rb +74 -0
  26. data/lib/turba_kit/default.rb +102 -0
  27. data/lib/turba_kit/error.rb +209 -0
  28. data/lib/turba_kit/response/raise_error.rb +20 -0
  29. data/lib/turba_kit/version.rb +3 -0
  30. data/lib/turba_kit.rb +27 -0
  31. data/spec/cassettes/TurbaKit_Client_Categories/_categories/handles_the_country_code_option.json +1 -0
  32. data/spec/cassettes/TurbaKit_Client_Categories/_category/returns_a_category.json +1 -0
  33. data/spec/cassettes/TurbaKit_Client_Categories/_create_category/creates_a_category.json +1 -0
  34. data/spec/cassettes/TurbaKit_Client_Categories/_delete_category/deletes_a_category_and_returns_true.json +1 -0
  35. data/spec/cassettes/TurbaKit_Client_Categories/_delete_category/returns_false_if_category_doesn_t_exist.json +1 -0
  36. data/spec/cassettes/TurbaKit_Client_Categories/_update_category/updates_a_category.json +1 -0
  37. data/spec/cassettes/TurbaKit_Client_Contents/_create_content/creates_a_content.json +1 -0
  38. data/spec/cassettes/TurbaKit_Client_Contents/_delete_content/deletes_a_content.json +1 -0
  39. data/spec/cassettes/TurbaKit_Client_Contents/_service_content/returns_a_content.json +1 -0
  40. data/spec/cassettes/TurbaKit_Client_Contents/_service_contents/lists_contents.json +1 -0
  41. data/spec/cassettes/TurbaKit_Client_Contents/_update_content/updates_a_content.json +1 -0
  42. data/spec/cassettes/TurbaKit_Client_Countries/_countries/returns_all_countries.json +1 -0
  43. data/spec/cassettes/TurbaKit_Client_Countries/_country/returns_a_country.json +1 -0
  44. data/spec/cassettes/TurbaKit_Client_Crowds/_create_crowd/creates_a_crowd.json +1 -0
  45. data/spec/cassettes/TurbaKit_Client_Crowds/_delete_crowd/deletes_a_crowd.json +1 -0
  46. data/spec/cassettes/TurbaKit_Client_Crowds/_service_crowd/returns_a_crowd.json +1 -0
  47. data/spec/cassettes/TurbaKit_Client_Crowds/_service_crowds/lists_crowds.json +1 -0
  48. data/spec/cassettes/TurbaKit_Client_Crowds/_update_crowd/updates_a_crowd.json +1 -0
  49. data/spec/cassettes/TurbaKit_Client_Links/_create_link/creates_a_link.json +1 -0
  50. data/spec/cassettes/TurbaKit_Client_Links/_delete_link/deletes_a_link.json +1 -0
  51. data/spec/cassettes/TurbaKit_Client_Links/_service_link/returns_a_link.json +1 -0
  52. data/spec/cassettes/TurbaKit_Client_Links/_service_links/lists_links.json +1 -0
  53. data/spec/cassettes/TurbaKit_Client_Links/_update_link/updates_a_link.json +1 -0
  54. data/spec/cassettes/TurbaKit_Client_Notifications/_create_notification/creates_a_notification.json +1 -0
  55. data/spec/cassettes/TurbaKit_Client_Notifications/_delete_notification/deletes_a_notification.json +1 -0
  56. data/spec/cassettes/TurbaKit_Client_Notifications/_service_notification/returns_a_notification.json +1 -0
  57. data/spec/cassettes/TurbaKit_Client_Notifications/_service_notifications/lists_notifications.json +1 -0
  58. data/spec/cassettes/TurbaKit_Client_Notifications/_update_notification/updates_a_notification.json +1 -0
  59. data/spec/cassettes/TurbaKit_Client_Organismes/_create_organisme/creates_an_organisme.json +1 -0
  60. data/spec/cassettes/TurbaKit_Client_Organismes/_delete_organisme/deletes_a_organisme_and_returns_true.json +1 -0
  61. data/spec/cassettes/TurbaKit_Client_Organismes/_delete_organisme/returns_false_if_organisme_doesn_t_exist.json +1 -0
  62. data/spec/cassettes/TurbaKit_Client_Organismes/_organisme/returns_a_organisme.json +1 -0
  63. data/spec/cassettes/TurbaKit_Client_Organismes/_organismes/handles_the_country_code_option.json +1 -0
  64. data/spec/cassettes/TurbaKit_Client_Organismes/_update_organisme/updates_an_organisme.json +1 -0
  65. data/spec/cassettes/TurbaKit_Client_Phonenumbers/_create_phonenumber/creates_a_phonenumber.json +1 -0
  66. data/spec/cassettes/TurbaKit_Client_Phonenumbers/_delete_phonenumber/deletes_a_phonenumber.json +1 -0
  67. data/spec/cassettes/TurbaKit_Client_Phonenumbers/_service_phonenumber/returns_a_phonenumber.json +1 -0
  68. data/spec/cassettes/TurbaKit_Client_Phonenumbers/_service_phonenumbers/lists_phonenumbers.json +1 -0
  69. data/spec/cassettes/TurbaKit_Client_Phonenumbers/_update_phonenumber/updates_a_phonenumber.json +1 -0
  70. data/spec/cassettes/TurbaKit_Client_Places/_create_place/creates_a_place.json +1 -0
  71. data/spec/cassettes/TurbaKit_Client_Places/_delete_place/deletes_a_place.json +1 -0
  72. data/spec/cassettes/TurbaKit_Client_Places/_service_place/returns_a_place.json +1 -0
  73. data/spec/cassettes/TurbaKit_Client_Places/_service_places/lists_places.json +1 -0
  74. data/spec/cassettes/TurbaKit_Client_Places/_update_place/updates_a_place.json +1 -0
  75. data/spec/cassettes/TurbaKit_Client_Services/_service/returns_a_service.json +1 -0
  76. data/spec/cassettes/TurbaKit_Client_Services/_services/handles_the_country_code_option.json +1 -0
  77. data/spec/cassettes/TurbaKit_Client_Tips/_create_tip/creates_a_tip.json +1 -0
  78. data/spec/cassettes/TurbaKit_Client_Tips/_delete_tip/deletes_a_tip.json +1 -0
  79. data/spec/cassettes/TurbaKit_Client_Tips/_service_tip/returns_a_tip.json +1 -0
  80. data/spec/cassettes/TurbaKit_Client_Tips/_service_tips/lists_tips.json +1 -0
  81. data/spec/cassettes/TurbaKit_Client_Tips/_update_tip/updates_a_tip.json +1 -0
  82. data/spec/cassettes/Turkit_Client_Categories/_categories/handles_the_country_code_option.json +1 -0
  83. data/spec/cassettes/Turkit_Client_Categories/_categories/returns_all_categories.json +1 -0
  84. data/spec/cassettes/Turkit_Client_Categories/_category/returns_a_category.json +1 -0
  85. data/spec/cassettes/Turkit_Client_Categories/_create_category/creates_a_category.json +1 -0
  86. data/spec/cassettes/Turkit_Client_Categories/_delete_category/deletes_a_category_and_returns_true.json +1 -0
  87. data/spec/cassettes/Turkit_Client_Categories/_delete_category/returns_false_if_category_doesn_t_exist.json +1 -0
  88. data/spec/cassettes/Turkit_Client_Categories/_search_category/returns_a_list_of_categories.json +1 -0
  89. data/spec/cassettes/Turkit_Client_Categories/_update_category/updates_a_category.json +1 -0
  90. data/spec/cassettes/Turkit_Client_Contents/_create_content/creates_a_content.json +1 -0
  91. data/spec/cassettes/Turkit_Client_Contents/_delete_content/deletes_a_content.json +1 -0
  92. data/spec/cassettes/Turkit_Client_Contents/_service_content/returns_a_content.json +1 -0
  93. data/spec/cassettes/Turkit_Client_Contents/_service_contents/lists_contents.json +1 -0
  94. data/spec/cassettes/Turkit_Client_Contents/_update_content/updates_a_content.json +1 -0
  95. data/spec/cassettes/Turkit_Client_Countries/_countries/returns_all_countries.json +1 -0
  96. data/spec/cassettes/Turkit_Client_Countries/_country/returns_a_country.json +1 -0
  97. data/spec/cassettes/Turkit_Client_Crowds/_create_crowd/creates_a_crowd.json +1 -0
  98. data/spec/cassettes/Turkit_Client_Crowds/_delete_crowd/deletes_a_crowd.json +1 -0
  99. data/spec/cassettes/Turkit_Client_Crowds/_service_crowd/returns_a_crowd.json +1 -0
  100. data/spec/cassettes/Turkit_Client_Crowds/_service_crowds/lists_crowds.json +1 -0
  101. data/spec/cassettes/Turkit_Client_Crowds/_update_crowd/updates_a_crowd.json +1 -0
  102. data/spec/cassettes/Turkit_Client_Links/_create_link/creates_a_link.json +1 -0
  103. data/spec/cassettes/Turkit_Client_Links/_delete_link/deletes_a_link.json +1 -0
  104. data/spec/cassettes/Turkit_Client_Links/_service_link/returns_a_link.json +1 -0
  105. data/spec/cassettes/Turkit_Client_Links/_service_links/lists_links.json +1 -0
  106. data/spec/cassettes/Turkit_Client_Links/_update_link/updates_a_link.json +1 -0
  107. data/spec/cassettes/Turkit_Client_Notifications/_create_notification/creates_a_notification.json +1 -0
  108. data/spec/cassettes/Turkit_Client_Notifications/_delete_notification/deletes_a_notification.json +1 -0
  109. data/spec/cassettes/Turkit_Client_Notifications/_service_notification/returns_a_notification.json +1 -0
  110. data/spec/cassettes/Turkit_Client_Notifications/_service_notifications/lists_notifications.json +1 -0
  111. data/spec/cassettes/Turkit_Client_Notifications/_update_notification/updates_a_notification.json +1 -0
  112. data/spec/cassettes/Turkit_Client_Organismes/_create_organisme/creates_an_organisme.json +1 -0
  113. data/spec/cassettes/Turkit_Client_Organismes/_delete_organisme/deletes_a_organisme_and_returns_true.json +1 -0
  114. data/spec/cassettes/Turkit_Client_Organismes/_delete_organisme/returns_false_if_organisme_doesn_t_exist.json +1 -0
  115. data/spec/cassettes/Turkit_Client_Organismes/_organisme/returns_a_organisme.json +1 -0
  116. data/spec/cassettes/Turkit_Client_Organismes/_organismes/handles_the_country_code_option.json +1 -0
  117. data/spec/cassettes/Turkit_Client_Organismes/_organismes/returns_all_organismes.json +1 -0
  118. data/spec/cassettes/Turkit_Client_Organismes/_search_organisme/returns_a_list_of_organismes.json +1 -0
  119. data/spec/cassettes/Turkit_Client_Organismes/_update_organisme/updates_an_organisme.json +1 -0
  120. data/spec/cassettes/Turkit_Client_Phonenumbers/_create_phonenumber/creates_a_phonenumber.json +1 -0
  121. data/spec/cassettes/Turkit_Client_Phonenumbers/_delete_phonenumber/deletes_a_phonenumber.json +1 -0
  122. data/spec/cassettes/Turkit_Client_Phonenumbers/_service_phonenumber/returns_a_phonenumber.json +1 -0
  123. data/spec/cassettes/Turkit_Client_Phonenumbers/_service_phonenumbers/lists_phonenumbers.json +1 -0
  124. data/spec/cassettes/Turkit_Client_Phonenumbers/_update_phonenumber/updates_a_phonenumber.json +1 -0
  125. data/spec/cassettes/Turkit_Client_Places/_create_place/creates_a_place.json +1 -0
  126. data/spec/cassettes/Turkit_Client_Places/_delete_place/deletes_a_place.json +1 -0
  127. data/spec/cassettes/Turkit_Client_Places/_service_place/returns_a_place.json +1 -0
  128. data/spec/cassettes/Turkit_Client_Places/_service_places/lists_places.json +1 -0
  129. data/spec/cassettes/Turkit_Client_Places/_update_place/updates_a_place.json +1 -0
  130. data/spec/cassettes/Turkit_Client_Services/_search_service/returns_a_list_of_services.json +1 -0
  131. data/spec/cassettes/Turkit_Client_Services/_service/returns_a_service.json +1 -0
  132. data/spec/cassettes/Turkit_Client_Services/_services/handles_the_country_code_option.json +1 -0
  133. data/spec/cassettes/Turkit_Client_Services/_services/returns_all_services.json +1 -0
  134. data/spec/cassettes/Turkit_Client_Tips/_create_tip/creates_a_tip.json +1 -0
  135. data/spec/cassettes/Turkit_Client_Tips/_delete_tip/deletes_a_tip.json +1 -0
  136. data/spec/cassettes/Turkit_Client_Tips/_service_tip/returns_a_tip.json +1 -0
  137. data/spec/cassettes/Turkit_Client_Tips/_service_tips/lists_tips.json +1 -0
  138. data/spec/cassettes/Turkit_Client_Tips/_update_tip/updates_a_tip.json +1 -0
  139. data/spec/lib/categories_spec.rb +64 -0
  140. data/spec/lib/contents_spec.rb +47 -0
  141. data/spec/lib/countries_spec.rb +23 -0
  142. data/spec/lib/crowds_spec.rb +47 -0
  143. data/spec/lib/links_spec.rb +47 -0
  144. data/spec/lib/notifications_spec.rb +47 -0
  145. data/spec/lib/organismes_spec.rb +64 -0
  146. data/spec/lib/phonenumbers_spec.rb +47 -0
  147. data/spec/lib/place_spec.rb +47 -0
  148. data/spec/lib/services_spec.rb +64 -0
  149. data/spec/lib/tips_spec.rb +47 -0
  150. data/spec/spec_helper.rb +34 -0
  151. data/turba_kit.gemspec +24 -0
  152. metadata +356 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 032cbfe91ba7465a1f61586f8147bf6745c64bdc
4
+ data.tar.gz: ff76c291e3c7ef08df77e3dd9c0a3b700d2f7001
5
+ SHA512:
6
+ metadata.gz: a713192585164fe8fba1633340d652235e409e23956ab031ef0f0498893487d56ad2b80b00035efd6c3f5fb1da45c7dc5458537f43cea89f6f738cec28969a3c
7
+ data.tar.gz: 9f2369295552e66e3cd1ee5be8538f38d9469382dc884eea2a2fe84ac464cea72ac755e0e7f12d8ee001dee61b1ef73b8b94c451a7d0ce8d7fb2d98ab9182883
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake'
4
+ gem 'faraday'
5
+ gem 'sawyer'
6
+
7
+ group :test do
8
+ gem 'webmock'
9
+ gem 'vcr'
10
+ gem 'turn'
11
+ gem 'rake'
12
+ gem 'rspec', '~> 3.0.0.beta2'
13
+ end
14
+
15
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Joffrey JAFFEUX
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ # TurbaKit
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :test => :spec
8
+ task :default => :spec
9
+
10
+ namespace :doc do
11
+ begin
12
+ require 'yard'
13
+ YARD::Rake::YardocTask.new do |task|
14
+ task.files = ['README.md', 'LICENSE.md', 'lib/**/*.rb']
15
+ task.options = [
16
+ '--output-dir', 'doc/yard',
17
+ '--markup', 'markdown',
18
+ ]
19
+ end
20
+ rescue LoadError
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ module TurbaKit
2
+
3
+ # Extracts options from method arguments
4
+ # @private
5
+ class Arguments < Array
6
+ attr_reader :options
7
+
8
+ def initialize(args)
9
+ @options = args.last.is_a?(::Hash) ? args.pop : {}
10
+ super(args)
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ module TurbaKit
2
+
3
+ # Authentication methods for {TurbaKit::Client}
4
+ module Authentication
5
+
6
+ def api_key_authenticated?
7
+ !!@api_key
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,41 @@
1
+ module TurbaKit
2
+ class Client
3
+ module Categories
4
+ def category(id_or_uri_id, *args)
5
+ get("categories/#{id_or_uri_id}?#{query_string(args)}")[:category]
6
+ end
7
+
8
+ def categories(*args)
9
+ get("categories?#{query_string(args)}")[:categories]
10
+ end
11
+
12
+ def create_category(params)
13
+ params = {category: params}
14
+ post("categories", options.merge(params))[:category]
15
+ end
16
+
17
+ def delete_category(id_or_uri_id)
18
+ boolean_from_response :delete, "categories/#{id_or_uri_id}", options
19
+ end
20
+
21
+ def search_category(query, *args)
22
+ get("categories?q=#{query}&#{query_string(args)}")[:categories]
23
+ end
24
+
25
+ # Update a category
26
+ #
27
+ # @param id_or_uri_id [String] ID of the category
28
+ # @param params [Hash] A customizable set of params.
29
+ # @option category_params [String] :title Category title.
30
+ # @option category_params [String] :url Category URL.
31
+ # @option category_params [String] :country_code Category country code.
32
+ # @return [Sawyer::Resource] The updated category
33
+ # @see https://github.com/turba-webservices/api-documentation/blob/master/v2/sections/categories.md#update-category
34
+ # @example Change the title of Category xxxxxx
35
+ # TurbaKit.update_issue("xxxxxx", {title: "A new title"})
36
+ def update_category(id_or_uri_id, category_params = {})
37
+ put("categories/#{id_or_uri_id}", options.merge({category: category_params}))[:category]
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,14 @@
1
+ module TurbaKit
2
+ class Client
3
+ module Checkins
4
+ def create_wait_checkin(service_id, wait)
5
+ post("services/#{service_id}/checkins?wait=#{wait}")
6
+ end
7
+
8
+ def recent_checkins(limit = 5, since)
9
+ since ||= 10.days.ago
10
+ get("checkins?limit=#{limit}&since=#{since}")
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ module TurbaKit
2
+ class Client
3
+ module Comments
4
+ def comments(page_url, domain, shortname, disqus_api_key)
5
+ get("comments?disqus_api_key=#{disqus_api_key}&url=#{page_url}&domain=#{domain}&disqus_shortname=#{shortname}")[:comments]
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,26 @@
1
+ module TurbaKit
2
+ class Client
3
+ module Contents
4
+ def service_content(service_id, content_id)
5
+ get("services/#{service_id}/contents/#{content_id}")[:content]
6
+ end
7
+
8
+ def service_contents(service_id)
9
+ get("services/#{service_id}/contents")[:contents]
10
+ end
11
+
12
+ def create_content(service_id, params, options = {})
13
+ # params = {type: type}
14
+ post("services/#{service_id}/contents", {content: options.merge(params)})[:content]
15
+ end
16
+
17
+ def update_content(service_id, content_id, *args)
18
+ put("services/#{service_id}/contents/#{content_id}", {content: options.merge(args[0])})[:content]
19
+ end
20
+
21
+ def delete_content(service_id, content_id)
22
+ boolean_from_response :delete, "services/#{service_id}/contents/#{content_id}", options
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ module TurbaKit
2
+ class Client
3
+ module Countries
4
+ def country(country_code)
5
+ countries = get("countries")[:countries]
6
+ countries.select{|k, v| k[:country_code] == country_code}.first
7
+ end
8
+
9
+ def countries
10
+ get("countries")[:countries]
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,25 @@
1
+ module TurbaKit
2
+ class Client
3
+ module CrowdTable
4
+ def service_crowd_table(service_id)
5
+ get("services/#{service_id}/crowd_table")[:crowd_table]
6
+ end
7
+
8
+ def create_crowd_table(service_id, params, options = {})
9
+ post("services/#{service_id}/crowd_table", {crowd_table: options.merge(params)})[:crowd_table]
10
+ end
11
+
12
+ def update_crowd_table(service_id, crowd_id, *args)
13
+ put("services/#{service_id}/crowd_table", {crowd_table: options.merge(args[0])})[:crowd_table]
14
+ end
15
+
16
+ def delete_crowd_table(service_id, crowd_id)
17
+ boolean_from_response :delete, "services/#{service_id}/crowd_table", options
18
+ end
19
+
20
+ def copy_crowd_table(service_id, services_ids)
21
+ boolean_from_response :post, "services/#{service_id}/crowd_table/copy/#{services_ids}", options
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,26 @@
1
+ module TurbaKit
2
+ class Client
3
+ module Links
4
+ def service_link(service_id, link_id)
5
+ get("services/#{service_id}/links/#{link_id}")[:link]
6
+ end
7
+
8
+ def service_links(service_id)
9
+ get("services/#{service_id}/links")[:links]
10
+ end
11
+
12
+ def create_link(service_id, params, options = {})
13
+ # params = {text: text, url: url}
14
+ post("services/#{service_id}/links", {link: options.merge(params)})[:link]
15
+ end
16
+
17
+ def update_link(service_id, link_id, *args)
18
+ put("services/#{service_id}/links/#{link_id}", {link: options.merge(args[0])})[:link]
19
+ end
20
+
21
+ def delete_link(service_id, link_id)
22
+ boolean_from_response :delete, "services/#{service_id}/links/#{link_id}", options
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,15 @@
1
+ module TurbaKit
2
+ class Client
3
+ module Migrations
4
+ def create_service_child(service_id)
5
+ params = {origin_id: service_id, migration: 'add_new_child'}
6
+ post("migrations", options.merge(params))
7
+ end
8
+
9
+ def create_migration(params)
10
+ p params
11
+ post("migrations", params)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ module TurbaKit
2
+ class Client
3
+ module Notifications
4
+ def service_notification(service_id, notification_id)
5
+ get("services/#{service_id}/notifications/#{notification_id}")[:notification]
6
+ end
7
+
8
+ def service_notifications(service_id)
9
+ get("services/#{service_id}/notifications")[:notifications]
10
+ end
11
+
12
+ def create_notification(service_id, params, options = {})
13
+ # params = {text: text}
14
+ post("services/#{service_id}/notifications", {notification: options.merge(params)})[:notification]
15
+ end
16
+
17
+ def update_notification(service_id, notification_id, *args)
18
+ put("services/#{service_id}/notifications/#{notification_id}", {notification: options.merge(args[0])})[:notification]
19
+ end
20
+
21
+ def delete_notification(service_id, notification_id)
22
+ boolean_from_response :delete, "services/#{service_id}/notifications/#{notification_id}", options
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,41 @@
1
+ module TurbaKit
2
+ class Client
3
+ module Organismes
4
+ def organisme(id_or_uri_id, *args)
5
+ get("organismes/#{id_or_uri_id}?#{query_string(args)}")[:organisme]
6
+ end
7
+
8
+ def organismes(*args)
9
+ get("organismes?#{query_string(args)}")[:organismes]
10
+ end
11
+
12
+ def create_organisme(params)
13
+ params = {organisme: params}
14
+ post("organismes", options.merge(params))[:organisme]
15
+ end
16
+
17
+ def delete_organisme(id_or_uri_id)
18
+ boolean_from_response :delete, "organismes/#{id_or_uri_id}", options
19
+ end
20
+
21
+ def search_organisme(query, *args)
22
+ get("organismes?q=#{query}&#{query_string(args)}")[:organismes]
23
+ end
24
+
25
+ # Update an organisme
26
+ #
27
+ # @param id_or_uri_id [String] ID of the organisme
28
+ # @param params [Hash] A customizable set of params.
29
+ # @option organisme_params [String] :title Category title.
30
+ # @option organisme_params [String] :url Category URL.
31
+ # @option organisme_params [String] :country_code Category country code.
32
+ # @return [Sawyer::Resource] The updated organisme
33
+ # @see https://github.com/turba-webservices/api-documentation/blob/master/v2/sections/organismes.md#update-organisme
34
+ # @example Change the title of Category xxxxxx
35
+ # TurbaKit.update_issue("xxxxxx", {title: "A new title"})
36
+ def update_organisme(id_or_uri_id, organisme_params = {})
37
+ put("organismes/#{id_or_uri_id}", options.merge({organisme: organisme_params}))[:organisme]
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,26 @@
1
+ module TurbaKit
2
+ class Client
3
+ module Phonenumbers
4
+ def service_phonenumber(service_id, phonenumber_id)
5
+ get("services/#{service_id}/phonenumbers/#{phonenumber_id}")[:phonenumber]
6
+ end
7
+
8
+ def service_phonenumbers(service_id)
9
+ get("services/#{service_id}/phonenumbers")[:phonenumbers]
10
+ end
11
+
12
+ def create_phonenumber(service_id, params, options = {})
13
+ # params = {number: number, text: text}
14
+ post("services/#{service_id}/phonenumbers", {phonenumber: options.merge(params)})[:phonenumber]
15
+ end
16
+
17
+ def update_phonenumber(service_id, phonenumber_id, *args)
18
+ put("services/#{service_id}/phonenumbers/#{phonenumber_id}", {phonenumber: options.merge(args[0])})[:phonenumber]
19
+ end
20
+
21
+ def delete_phonenumber(service_id, phonenumber_id)
22
+ boolean_from_response :delete, "services/#{service_id}/phonenumbers/#{phonenumber_id}", options
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module TurbaKit
2
+ class Client
3
+ module Places
4
+ def service_place(service_id, place_id)
5
+ get("services/#{service_id}/places/#{place_id}")[:place]
6
+ end
7
+
8
+ def service_places(service_id)
9
+ get("services/#{service_id}/places")[:places]
10
+ end
11
+
12
+ def create_place(service_id, params, options = {})
13
+ # params = {text: text, country: country, city: city}
14
+ post("services/#{service_id}/places", {place: options.merge(params)})[:place]
15
+ end
16
+
17
+ def update_place(service_id, place_id, *args)
18
+ put("services/#{service_id}/places/#{place_id}", {place: options.merge(args[0])})[:place]
19
+ end
20
+
21
+ def delete_place(service_id, place_id)
22
+ boolean_from_response :delete, "services/#{service_id}/places/#{place_id}", options
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,9 @@
1
+ module TurbaKit
2
+ class Client
3
+ module Search
4
+ def search(query, *args)
5
+ get("search?q=#{query}&#{query_string(args)}")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,41 @@
1
+ module TurbaKit
2
+ class Client
3
+ module Services
4
+ def service(id_or_uri_id, *args)
5
+ get("services/#{id_or_uri_id}?#{query_string(args)}")[:service]
6
+ end
7
+
8
+ def services(*args)
9
+ get("services?#{query_string(args)}")[:services]
10
+ end
11
+
12
+ def create_service(params)
13
+ params = {service: params}
14
+ post("services", options.merge(params))[:service]
15
+ end
16
+
17
+ def delete_service(id_or_uri_id)
18
+ boolean_from_response :delete, "services/#{id_or_uri_id}", options
19
+ end
20
+
21
+ def search_service(query, *args)
22
+ get("services?q=#{query}&#{query_string(args)}")[:services]
23
+ end
24
+
25
+ # Update a service
26
+ #
27
+ # @param id_or_uri_id [String] ID of the service
28
+ # @param params [Hash] A customizable set of params.
29
+ # @option service_params [String] :title Category title.
30
+ # @option service_params [String] :url Category URL.
31
+ # @option service_params [String] :country_code Category country code.
32
+ # @return [Sawyer::Resource] The updated service
33
+ # @see https://github.com/turba-webservices/api-documentation/blob/master/v2/sections/services.md#update-service
34
+ # @example Change the title of Category xxxxxx
35
+ # TurbaKit.update_issue("xxxxxx", {title: "A new title"})
36
+ def update_service(id_or_uri_id, service_params = {})
37
+ put("services/#{id_or_uri_id}", options.merge({service: service_params}))[:service]
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,26 @@
1
+ module TurbaKit
2
+ class Client
3
+ module Tips
4
+ def service_tip(service_id, tip_id)
5
+ get("services/#{service_id}/tips/#{tip_id}")[:tip]
6
+ end
7
+
8
+ def service_tips(service_id)
9
+ get("services/#{service_id}/tips")[:tips]
10
+ end
11
+
12
+ def create_tip(service_id, params, options = {})
13
+ # params = {title: title, text: text}
14
+ post("services/#{service_id}/tips", {tip: options.merge(params)})[:tip]
15
+ end
16
+
17
+ def update_tip(service_id, tip_id, *args)
18
+ put("services/#{service_id}/tips/#{tip_id}", {tip: options.merge(args[0])})[:tip]
19
+ end
20
+
21
+ def delete_tip(service_id, tip_id)
22
+ boolean_from_response :delete, "services/#{service_id}/tips/#{tip_id}", options
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,168 @@
1
+ require 'sawyer'
2
+ require 'turba_kit/arguments'
3
+ require 'turba_kit/authentication'
4
+ require 'turba_kit/configurable'
5
+ require 'turba_kit/client/categories'
6
+ require 'turba_kit/client/organismes'
7
+ require 'turba_kit/client/services'
8
+ require 'turba_kit/client/countries'
9
+ require 'turba_kit/client/phonenumbers'
10
+ require 'turba_kit/client/contents'
11
+ require 'turba_kit/client/links'
12
+ require 'turba_kit/client/tips'
13
+ require 'turba_kit/client/places'
14
+ require 'turba_kit/client/notifications'
15
+ require 'turba_kit/client/crowd_table'
16
+ require 'turba_kit/client/comments'
17
+ require 'turba_kit/client/checkins'
18
+ require 'turba_kit/client/search'
19
+ require 'turba_kit/client/migrations'
20
+
21
+ module TurbaKit
22
+
23
+ # Client for the Turba API
24
+ #
25
+ # @see http://github.com/turba-webservices/turba_kit
26
+ class Client
27
+
28
+ include TurbaKit::Authentication
29
+ include TurbaKit::Configurable
30
+ include TurbaKit::Client::Categories
31
+ include TurbaKit::Client::Organismes
32
+ include TurbaKit::Client::Services
33
+ include TurbaKit::Client::Countries
34
+ include TurbaKit::Client::Phonenumbers
35
+ include TurbaKit::Client::Contents
36
+ include TurbaKit::Client::Links
37
+ include TurbaKit::Client::Tips
38
+ include TurbaKit::Client::Places
39
+ include TurbaKit::Client::Notifications
40
+ include TurbaKit::Client::CrowdTable
41
+ include TurbaKit::Client::Comments
42
+ include TurbaKit::Client::Checkins
43
+ include TurbaKit::Client::Search
44
+ include TurbaKit::Client::Migrations
45
+
46
+ # Header keys that can be passed in options hash to {#get},{#head}
47
+ CONVENIENCE_HEADERS = Set.new([:accept, :content_type])
48
+
49
+ def initialize(options = {})
50
+ TurbaKit::Configurable.keys.each do |key|
51
+ instance_variable_set(:"@#{key}", options[key] || TurbaKit.instance_variable_get(:"@#{key}"))
52
+ end
53
+ end
54
+
55
+ # Compares client options to a Hash of requested options
56
+ #
57
+ # @param opts [Hash] Options to compare with current client options
58
+ # @return [Boolean]
59
+ def same_options?(opts)
60
+ opts.hash == options.hash
61
+ end
62
+
63
+ # Text representation of the client, masking api key
64
+ #
65
+ # @return [String]
66
+ def inspect
67
+ inspected = super
68
+
69
+ # Only show last 4 of api key, secret
70
+ if @api_key
71
+ inspected = inspected.gsub! @api_key, "#{'*'*36}#{@api_key[36..-1]}"
72
+ end
73
+
74
+ inspected
75
+ end
76
+
77
+ def get(url, options = {})
78
+ request :get, url, parse_query_and_convenience_headers(options)
79
+ end
80
+
81
+ def post(url, options = {})
82
+ request :post, url, options
83
+ end
84
+
85
+ def put(url, options = {})
86
+ request :put, url, options
87
+ end
88
+
89
+ def delete(url, options = {})
90
+ request :delete, url, options
91
+ end
92
+
93
+ def last_response
94
+ @last_response if defined? @last_response
95
+ end
96
+
97
+ def agent
98
+ @agent ||= Sawyer::Agent.new("#{api_endpoint}#{api_version}/", sawyer_options) do |http|
99
+ http.headers[:accept] = default_media_type
100
+ http.headers[:user_agent] = user_agent
101
+ http.headers['X-API-KEY'] = api_key
102
+ end
103
+ end
104
+
105
+ # Fetch the root resource for the API
106
+ #
107
+ # @return [Sawyer::Resource]
108
+ def root
109
+ get "/"
110
+ end
111
+
112
+ private
113
+
114
+ def query_string(*args)
115
+ return if args.flatten.blank?
116
+ query_string = ''
117
+ arguments = TurbaKit::Arguments.new(args).flatten[0]
118
+ query_string = arguments.map {|k, v| "#{k}=#{v}"}.join('&')
119
+ query_string
120
+ end
121
+
122
+ def boolean_from_response(method, path, options = {})
123
+ request(method, path, options)
124
+ @last_response.status == 204
125
+ rescue TurbaKit::NotFound
126
+ false
127
+ end
128
+
129
+ def sawyer_options
130
+ opts = { links_parser: Sawyer::LinkParsers::Simple.new }
131
+ conn_opts = @connection_options
132
+ conn_opts[:builder] = @middleware if @middleware
133
+ conn_opts[:proxy] = @proxy if @proxy
134
+ opts[:faraday] = Faraday.new(conn_opts)
135
+ # opts[:serializer] = Sawyer::Serializer.message_pack
136
+ opts
137
+ end
138
+
139
+ def parse_query_and_convenience_headers(options)
140
+ headers = options.fetch(:headers, {})
141
+ CONVENIENCE_HEADERS.each do |h|
142
+ if header = options.delete(h)
143
+ headers[h] = header
144
+ end
145
+ end
146
+ query = options.delete(:query)
147
+ opts = { query: options }
148
+ opts[:query].merge!(query) if query && query.is_a?(Hash)
149
+ opts[:headers] = headers unless headers.empty?
150
+
151
+ opts
152
+ end
153
+
154
+ def request(method, path, data, options = {})
155
+ if data.is_a?(Hash)
156
+ options[:query] = data.delete(:query) || {}
157
+ options[:headers] = data.delete(:headers) || {}
158
+ if accept = data.delete(:accept)
159
+ options[:headers][:accept] = accept
160
+ end
161
+ end
162
+
163
+ @last_response = response = agent.call(method, URI::Parser.new.escape(path.to_s), data, options)
164
+
165
+ response.data
166
+ end
167
+ end
168
+ end