tacokit 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +4 -0
  4. data/.travis.yml +3 -0
  5. data/Gemfile +2 -1
  6. data/README.md +140 -47
  7. data/Rakefile +13 -0
  8. data/bin/_guard-core +16 -0
  9. data/bin/console +14 -0
  10. data/bin/guard +16 -0
  11. data/bin/rake +16 -0
  12. data/bin/rspec +16 -0
  13. data/bin/rubocop +16 -0
  14. data/bin/setup +7 -0
  15. data/lib/tacokit/authorization.rb +8 -9
  16. data/lib/tacokit/client.rb +14 -20
  17. data/lib/tacokit/client/actions.rb +30 -14
  18. data/lib/tacokit/client/boards.rb +112 -16
  19. data/lib/tacokit/client/cards.rb +251 -72
  20. data/lib/tacokit/client/checklists.rb +25 -14
  21. data/lib/tacokit/client/labels.rb +11 -4
  22. data/lib/tacokit/client/lists.rb +66 -13
  23. data/lib/tacokit/client/members.rb +118 -42
  24. data/lib/tacokit/client/notifications.rb +29 -2
  25. data/lib/tacokit/client/organizations.rb +13 -5
  26. data/lib/tacokit/client/searches.rb +17 -2
  27. data/lib/tacokit/client/tokens.rb +8 -2
  28. data/lib/tacokit/client/types.rb +4 -2
  29. data/lib/tacokit/client/webhooks.rb +17 -4
  30. data/lib/tacokit/collection.rb +6 -5
  31. data/lib/tacokit/configuration.rb +10 -2
  32. data/lib/tacokit/middleware.rb +16 -0
  33. data/lib/tacokit/resource.rb +7 -6
  34. data/lib/tacokit/transform.rb +2 -4
  35. data/lib/tacokit/utils.rb +7 -4
  36. data/lib/tacokit/version.rb +2 -1
  37. data/tacokit.gemspec +4 -4
  38. metadata +17 -273
  39. data/spec/cassettes/Tacokit_Client/_connection/authorized_GET_request_with_app_key_and_token_params.json +0 -1
  40. data/spec/cassettes/Tacokit_Client_Actions/_action/returns_a_token_authorized_action.json +0 -1
  41. data/spec/cassettes/Tacokit_Client_Actions/_action/returns_oauth_authorized_board.json +0 -1
  42. data/spec/cassettes/Tacokit_Client_Actions/_action_board/returns_action_board.json +0 -1
  43. data/spec/cassettes/Tacokit_Client_Actions/_action_card/returns_action_card.json +0 -1
  44. data/spec/cassettes/Tacokit_Client_Actions/_action_entities/returns_action_entities.json +0 -1
  45. data/spec/cassettes/Tacokit_Client_Actions/_action_list/returns_action_list.json +0 -1
  46. data/spec/cassettes/Tacokit_Client_Actions/_delete_action/deletes_an_action.json +0 -1
  47. data/spec/cassettes/Tacokit_Client_Actions/_update_action/updates_an_action.json +0 -1
  48. data/spec/cassettes/Tacokit_Client_Actions/_update_action_text/updates_an_action.json +0 -1
  49. data/spec/cassettes/Tacokit_Client_Boards/_add_board_member/adds_invites_member_to_board.json +0 -1
  50. data/spec/cassettes/Tacokit_Client_Boards/_board/returns_a_token_authorized_board.json +0 -1
  51. data/spec/cassettes/Tacokit_Client_Boards/_board/returns_oauth_authorized_board.json +0 -1
  52. data/spec/cassettes/Tacokit_Client_Boards/_board_actions/returns_board_actions.json +0 -1
  53. data/spec/cassettes/Tacokit_Client_Boards/_board_cards/returns_board_cards.json +0 -1
  54. data/spec/cassettes/Tacokit_Client_Boards/_board_checklists/returns_board_checklists.json +0 -1
  55. data/spec/cassettes/Tacokit_Client_Boards/_board_labels/returns_board_labels.json +0 -1
  56. data/spec/cassettes/Tacokit_Client_Boards/_board_lists/returns_board_lists.json +0 -1
  57. data/spec/cassettes/Tacokit_Client_Boards/_board_members/returns_board_members.json +0 -1
  58. data/spec/cassettes/Tacokit_Client_Boards/_board_organization/returns_board_organization.json +0 -1
  59. data/spec/cassettes/Tacokit_Client_Boards/_board_preferences/returns_preferences_for_a_board.json +0 -1
  60. data/spec/cassettes/Tacokit_Client_Boards/_board_stars/returns_board_stars.json +0 -1
  61. data/spec/cassettes/Tacokit_Client_Boards/_update_board/updates_a_board.json +0 -1
  62. data/spec/cassettes/Tacokit_Client_Boards/_update_board/updates_nested_resource.json +0 -1
  63. data/spec/cassettes/Tacokit_Client_Boards/_update_board_member/updates_member.json +0 -1
  64. data/spec/cassettes/Tacokit_Client_Cards/_add_comment/creates_a_comment.json +0 -1
  65. data/spec/cassettes/Tacokit_Client_Cards/_add_label/adds_label_to_card.json +0 -1
  66. data/spec/cassettes/Tacokit_Client_Cards/_add_member_to_card/adds_member_to_card.json +0 -1
  67. data/spec/cassettes/Tacokit_Client_Cards/_archive_card/archives_card.json +0 -1
  68. data/spec/cassettes/Tacokit_Client_Cards/_archive_card/restore_card.json +0 -1
  69. data/spec/cassettes/Tacokit_Client_Cards/_attachments/returns_an_attachment.json +0 -1
  70. data/spec/cassettes/Tacokit_Client_Cards/_attachments/returns_attachments.json +0 -1
  71. data/spec/cassettes/Tacokit_Client_Cards/_card/returns_a_card_by_card_resource.json +0 -1
  72. data/spec/cassettes/Tacokit_Client_Cards/_card/returns_a_card_by_id.json +0 -1
  73. data/spec/cassettes/Tacokit_Client_Cards/_card/returns_a_card_by_short_link.json +0 -1
  74. data/spec/cassettes/Tacokit_Client_Cards/_card_actions/returns_card_actions.json +0 -1
  75. data/spec/cassettes/Tacokit_Client_Cards/_card_board/returns_card_board.json +0 -1
  76. data/spec/cassettes/Tacokit_Client_Cards/_card_list/returns_a_list.json +0 -1
  77. data/spec/cassettes/Tacokit_Client_Cards/_card_members/returns_members.json +0 -1
  78. data/spec/cassettes/Tacokit_Client_Cards/_card_members/returns_members_voted.json +0 -1
  79. data/spec/cassettes/Tacokit_Client_Cards/_checklists/returns_check_item_states.json +0 -1
  80. data/spec/cassettes/Tacokit_Client_Cards/_checklists/returns_checklists.json +0 -1
  81. data/spec/cassettes/Tacokit_Client_Cards/_create_card/creates_a_card.json +0 -1
  82. data/spec/cassettes/Tacokit_Client_Cards/_create_card_attachment/attaches_external_url.json +0 -1
  83. data/spec/cassettes/Tacokit_Client_Cards/_create_card_attachment/uploads_local_file.json +0 -1
  84. data/spec/cassettes/Tacokit_Client_Cards/_delete_card/deletes_a_card.json +0 -1
  85. data/spec/cassettes/Tacokit_Client_Cards/_delete_comment/deletes_comment.json +0 -1
  86. data/spec/cassettes/Tacokit_Client_Cards/_move_card/moves_card_to_a_new_position.json +0 -1
  87. data/spec/cassettes/Tacokit_Client_Cards/_move_card/moves_card_to_another_board_list.json +0 -1
  88. data/spec/cassettes/Tacokit_Client_Cards/_move_card/moves_card_to_board.json +0 -1
  89. data/spec/cassettes/Tacokit_Client_Cards/_move_card/moves_card_to_list.json +0 -1
  90. data/spec/cassettes/Tacokit_Client_Cards/_move_card/raises_error_if_missing_options.json +0 -1
  91. data/spec/cassettes/Tacokit_Client_Cards/_start_checklist/adds_new_checklist_by_name.json +0 -1
  92. data/spec/cassettes/Tacokit_Client_Cards/_start_checklist/copies_a_checklist_by_id.json +0 -1
  93. data/spec/cassettes/Tacokit_Client_Cards/_stickers/returns_stickers.json +0 -1
  94. data/spec/cassettes/Tacokit_Client_Cards/_update_card/updates_a_card.json +0 -1
  95. data/spec/cassettes/Tacokit_Client_Cards/_update_checklist_item/updates_checklist_item.json +0 -1
  96. data/spec/cassettes/Tacokit_Client_Cards/_update_comment/updates_a_comment.json +0 -1
  97. data/spec/cassettes/Tacokit_Client_Cards/_vote/adds_a_member_s_vote_to_card.json +0 -1
  98. data/spec/cassettes/Tacokit_Client_Checklists/_check_items/adds_a_checklist_check_item.json +0 -1
  99. data/spec/cassettes/Tacokit_Client_Checklists/_check_items/retrieves_checklist_check_items.json +0 -1
  100. data/spec/cassettes/Tacokit_Client_Checklists/_checklist/returns_a_checklist_by_id.json +0 -1
  101. data/spec/cassettes/Tacokit_Client_Checklists/_create_checklist/creates_a_checklist.json +0 -1
  102. data/spec/cassettes/Tacokit_Client_Checklists/_delete_checklist/deletes_a_checklist.json +0 -1
  103. data/spec/cassettes/Tacokit_Client_Checklists/_update_checklist/updates_a_checklist.json +0 -1
  104. data/spec/cassettes/Tacokit_Client_Labels/_create_label/creates_a_label.json +0 -1
  105. data/spec/cassettes/Tacokit_Client_Labels/_delete_label/deletes_a_label.json +0 -1
  106. data/spec/cassettes/Tacokit_Client_Labels/_label/returns_a_label_by_id.json +0 -1
  107. data/spec/cassettes/Tacokit_Client_Labels/_update_label/updates_a_label.json +0 -1
  108. data/spec/cassettes/Tacokit_Client_Lists/_archive_list_cards/should_archive_cards_in_list.json +0 -1
  109. data/spec/cassettes/Tacokit_Client_Lists/_create_list/creates_a_list.json +0 -1
  110. data/spec/cassettes/Tacokit_Client_Lists/_list/returns_a_list_by_id.json +0 -1
  111. data/spec/cassettes/Tacokit_Client_Lists/_list_actions/returns_list_actions.json +0 -1
  112. data/spec/cassettes/Tacokit_Client_Lists/_list_board/returns_list_board.json +0 -1
  113. data/spec/cassettes/Tacokit_Client_Lists/_list_cards/returns_list_cards.json +0 -1
  114. data/spec/cassettes/Tacokit_Client_Lists/_move_list_cards/should_move_cards_in_list.json +0 -1
  115. data/spec/cassettes/Tacokit_Client_Lists/_update_list/updates_a_list.json +0 -1
  116. data/spec/cassettes/Tacokit_Client_Members/_actions/returns_member_actions.json +0 -1
  117. data/spec/cassettes/Tacokit_Client_Members/_boards/returns_for_me_with_options_as_first_arg.json +0 -1
  118. data/spec/cassettes/Tacokit_Client_Members/_boards/returns_member_boards.json +0 -1
  119. data/spec/cassettes/Tacokit_Client_Members/_cards/returns_member_cards.json +0 -1
  120. data/spec/cassettes/Tacokit_Client_Members/_member/accepts_a_resource.json +0 -1
  121. data/spec/cassettes/Tacokit_Client_Members/_member/authenticated/returns_self.json +0 -1
  122. data/spec/cassettes/Tacokit_Client_Members/_member/returns_a_member.json +0 -1
  123. data/spec/cassettes/Tacokit_Client_Members/_member/returns_self.json +0 -1
  124. data/spec/cassettes/Tacokit_Client_Members/_member/supports_query_fields_as_string_or_array.json +0 -1
  125. data/spec/cassettes/Tacokit_Client_Members/_notifications/returns_member_notifications.json +0 -1
  126. data/spec/cassettes/Tacokit_Client_Members/_organizations/returns_member_organizations.json +0 -1
  127. data/spec/cassettes/Tacokit_Client_Members/_tokens/returns_member_tokens.json +0 -1
  128. data/spec/cassettes/Tacokit_Client_Members/_update_member/updates_a_member.json +0 -1
  129. data/spec/cassettes/Tacokit_Client_Members/_update_member/updates_nested_resource.json +0 -1
  130. data/spec/cassettes/Tacokit_Client_Notifications/_notification/returns_a_notification_by_id.json +0 -1
  131. data/spec/cassettes/Tacokit_Client_Notifications/_update_notification/updates_a_notification.json +0 -1
  132. data/spec/cassettes/Tacokit_Client_Organizations/_create_organization/creates_a_organization.json +0 -1
  133. data/spec/cassettes/Tacokit_Client_Organizations/_delete_organization/deletes_a_organization.json +0 -1
  134. data/spec/cassettes/Tacokit_Client_Organizations/_organization/returns_an_organization_by_id.json +0 -1
  135. data/spec/cassettes/Tacokit_Client_Organizations/_organization_resource/returns_organization_actions.json +0 -1
  136. data/spec/cassettes/Tacokit_Client_Organizations/_organization_resource/returns_organization_boards.json +0 -1
  137. data/spec/cassettes/Tacokit_Client_Organizations/_organization_resource/returns_organization_members.json +0 -1
  138. data/spec/cassettes/Tacokit_Client_Organizations/_update_organization/updates_a_organization.json +0 -1
  139. data/spec/cassettes/Tacokit_Client_Searches/_search/returns_search_result.json +0 -1
  140. data/spec/cassettes/Tacokit_Client_Tokens/_delete_token/deletes_a_token.json +0 -1
  141. data/spec/cassettes/Tacokit_Client_Tokens/_token/returns_a_token_for_token_string.json +0 -1
  142. data/spec/cassettes/Tacokit_Client_Tokens/_token_resource/returns_token_member.json +0 -1
  143. data/spec/cassettes/Tacokit_Client_Tokens/_token_resource/returns_token_webhooks.json +0 -1
  144. data/spec/cassettes/Tacokit_Client_Types/_type/returns_a_type_by_id.json +0 -1
  145. data/spec/cassettes/Tacokit_Client_Webhooks/_create_webhook/creates_a_webhook.json +0 -1
  146. data/spec/cassettes/Tacokit_Client_Webhooks/_delete_webhook/deletes_a_webhook.json +0 -1
  147. data/spec/cassettes/Tacokit_Client_Webhooks/_update_webhook/updates_a_webhook.json +0 -1
  148. data/spec/cassettes/Tacokit_Client_Webhooks/_webhook/returns_a_webhook_by_short_link.json +0 -1
  149. data/spec/fixtures/taco.png +0 -0
  150. data/spec/spec_helper.rb +0 -171
  151. data/spec/tacokit/authorization_spec.rb +0 -47
  152. data/spec/tacokit/client/actions_spec.rb +0 -137
  153. data/spec/tacokit/client/boards_spec.rb +0 -171
  154. data/spec/tacokit/client/cards_spec.rb +0 -446
  155. data/spec/tacokit/client/checklists_spec.rb +0 -89
  156. data/spec/tacokit/client/labels_spec.rb +0 -62
  157. data/spec/tacokit/client/lists_spec.rb +0 -131
  158. data/spec/tacokit/client/members_spec.rb +0 -145
  159. data/spec/tacokit/client/notifications_spec.rb +0 -25
  160. data/spec/tacokit/client/organizations_spec.rb +0 -79
  161. data/spec/tacokit/client/searches_spec.rb +0 -11
  162. data/spec/tacokit/client/tokens_spec.rb +0 -33
  163. data/spec/tacokit/client/types_spec.rb +0 -11
  164. data/spec/tacokit/client/webhooks_spec.rb +0 -61
  165. data/spec/tacokit/client_spec.rb +0 -28
  166. data/spec/tacokit/configuration_spec.rb +0 -50
  167. data/spec/tacokit/middleware/raise_error_spec.rb +0 -34
  168. data/spec/tacokit/resource_spec.rb +0 -151
  169. data/spec/tacokit/transform_spec.rb +0 -133
  170. data/spec/tacokit_spec.rb +0 -14
@@ -1,79 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Tacokit::Client::Organizations do
4
- describe "#organization", :vcr do
5
- it "returns an organization by id" do
6
- org = app_client.organization(test_org_name)
7
-
8
- expect(org.name).to eq "teamtacokit"
9
- end
10
- end
11
-
12
- describe "#organization_resource", :vcr do
13
- it "returns organization actions" do
14
- actions = app_client.organization_resource(test_org_name, :actions)
15
-
16
- expect(actions).not_to be_empty
17
- end
18
-
19
- it "returns organization boards" do
20
- boards = app_client.organization_resource(test_org_name, :boards)
21
-
22
- expect(boards).not_to be_empty
23
-
24
- board = boards.first
25
- expect(board.name).to be_present
26
- end
27
-
28
- it "returns organization members" do
29
- members = app_client.organization_resource(test_org_name, :members)
30
-
31
- expect(members).not_to be_empty
32
-
33
- member = members.first
34
- expect(member.username).to be_present
35
- end
36
- end
37
-
38
- describe "#update_organization", :vcr do
39
- it "updates a organization" do
40
- organization = oauth_client.update_organization(test_org_name, desc: "This organization is for Tacokit collaboration")
41
-
42
- expect(organization.desc).to eq "This organization is for Tacokit collaboration"
43
- assert_requested :put, trello_url_template("organizations/#{test_org_name}")
44
- end
45
- end
46
-
47
- describe "#create_organization", :vcr do
48
- before do
49
- @organization = app_client.create_organization "Autoorganization", desc: "This is an autogenerated organization"
50
- end
51
-
52
- it "creates a organization" do
53
- expect(@organization.display_name).to eq "Autoorganization"
54
- expect(@organization.desc).to eq "This is an autogenerated organization"
55
- assert_requested :post, trello_url_template("organizations{?key,token}"),
56
- body: {
57
- "displayName" => "Autoorganization",
58
- "desc" => "This is an autogenerated organization"
59
- }
60
- end
61
-
62
- after do
63
- app_client.delete_organization(@organization.id)
64
- end
65
- end
66
-
67
- describe "#delete_organization", :vcr do
68
- before do
69
- @organization = app_client.create_organization "Autoorganization"
70
- end
71
-
72
- it "deletes a organization" do
73
- app_client.delete_organization(@organization.id)
74
-
75
- assert_requested :delete, trello_url_template("organizations/#{@organization.id}{?key,token}")
76
- expect { app_client.organization(@organization.id) }.to raise_error(Tacokit::Error::ResourceNotFound)
77
- end
78
- end
79
- end
@@ -1,11 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Tacokit::Client::Searches do
4
- describe "#search", :vcr do
5
- it "returns search result" do
6
- search = app_client.search("taco")
7
-
8
- expect(search.members).to_not be_empty
9
- end
10
- end
11
- end
@@ -1,33 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Tacokit::Client::Tokens do
4
- describe "#token", :vcr do
5
- it "returns a token for token string" do
6
- token = app_client.token(test_trello_app_token)
7
-
8
- expect(token.identifier).to be_present
9
- end
10
- end
11
-
12
- describe "#token_resource", :vcr do
13
- it "returns token member" do
14
- member = app_client.token_resource(test_trello_app_token, :member)
15
-
16
- expect(member).to be_present
17
- end
18
-
19
- it "returns token webhooks" do
20
- webhooks = app_client.token_resource(test_trello_app_token, :webhooks)
21
-
22
- expect(webhooks).to be_any
23
- end
24
- end
25
-
26
- describe "#delete_token", :vcr do
27
- it "deletes a token" do
28
- expect { app_client.delete_token("faketokenid") }.to raise_error(Tacokit::Error) # 400, invalid token
29
-
30
- assert_requested :delete, trello_url_template("tokens/faketokenid{?key,token}")
31
- end
32
- end
33
- end
@@ -1,11 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Tacokit::Client::Types do
4
- describe "#type", :vcr do
5
- it "returns a type by id" do
6
- type = app_client.type(test_org_name)
7
-
8
- expect(type.type).to eq "organization"
9
- end
10
- end
11
- end
@@ -1,61 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Tacokit::Client::Webhooks do
4
- describe "#update_webhook", :vcr do
5
- before do
6
- @webhook = app_client.create_webhook \
7
- test_trello_app_token,
8
- test_org_id,
9
- tacokit_web_endpoint("webhook?create_webhook")
10
- end
11
-
12
- it "updates a webhook" do
13
- @webhook = app_client.update_webhook(@webhook.id, description: "This webhook is for Tacokit testing")
14
-
15
- expect(@webhook.description).to eq "This webhook is for Tacokit testing"
16
- assert_requested :put, trello_url_template("webhooks/#{@webhook.id}{?key,token}")
17
- end
18
-
19
- after do
20
- app_client.delete_webhook(@webhook.id)
21
- end
22
- end
23
-
24
- describe "#create_webhook", :vcr do
25
- before do
26
- @webhook = app_client.create_webhook \
27
- test_trello_app_token,
28
- test_org_id,
29
- tacokit_web_endpoint("webhook?create_webhook")
30
- end
31
-
32
- it "creates a webhook" do
33
- expect(@webhook.callback_url).to match(%r{https://[^/]*/webhook})
34
- assert_requested :post, trello_url_template("webhooks{?key,token}"),
35
- body: {
36
- "callbackURL" => tacokit_web_endpoint("webhook?create_webhook"),
37
- "idModel" => test_org_id
38
- }
39
- end
40
-
41
- after do
42
- app_client.delete_webhook(@webhook.id)
43
- end
44
- end
45
-
46
- describe "#delete_webhook", :vcr do
47
- before do
48
- @webhook = app_client.create_webhook \
49
- test_trello_app_token,
50
- test_org_id,
51
- tacokit_web_endpoint("webhook?delete_webhook")
52
- end
53
-
54
- it "deletes a webhook" do
55
- app_client.delete_webhook(@webhook.id)
56
-
57
- expect { app_client.token_resource(test_trello_app_token, :webhooks, @webhook.id) }.to raise_error(Tacokit::Error::ResourceNotFound)
58
- assert_requested :delete, trello_url_template("webhooks/#{@webhook.id}{?key,token}")
59
- end
60
- end
61
- end
@@ -1,28 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Tacokit::Client do
4
- describe "#configuration" do
5
- it "accepts configuration" do
6
- opts = { app_key: "joel", app_secret: "0ns0ftw@re" }
7
- client = Tacokit::Client.new(opts)
8
- expect(client.app_key).to eq("joel")
9
- expect(client.app_secret).to eq("0ns0ftw@re")
10
- end
11
- end
12
-
13
- describe "#connection", :vcr do
14
- it "authorized GET request with app key and token params" do
15
- client = Tacokit::Client.new(test_client_credentials)
16
- boards = client.get("members/me/boards")
17
-
18
- board = boards.detect { |b| b.name =~ /^Test Board/ }
19
-
20
- expect(board.name).to eq "Test Board"
21
- assert_requested :get, trello_url_template("members/me/boards{?key,token}")
22
- end
23
- end
24
-
25
- describe "#inspect" do
26
- it { expect(Tacokit::Client.new({}).inspect).to match %r{Tacokit::Client} }
27
- end
28
- end
@@ -1,50 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Tacokit::Configuration do
4
- let(:configuration) { Tacokit::Configuration.new }
5
-
6
- it "has an app_key attribute" do
7
- configuration.app_key = "app_key"
8
- expect(configuration.app_key).to eq("app_key")
9
- end
10
-
11
- it "has an app_secret attribute" do
12
- configuration.app_secret = "app_secret"
13
- expect(configuration.app_secret).to eq("app_secret")
14
- end
15
-
16
- it "has an oauth_token attribute" do
17
- configuration.oauth_token = "oauth_token"
18
- expect(configuration.oauth_token).to eq("oauth_token")
19
- end
20
-
21
- it "has an oauth_token_secret attribute" do
22
- configuration.oauth_secret = "oauth_secret"
23
- expect(configuration.oauth_secret).to eq("oauth_secret")
24
- end
25
-
26
- it "has a developer public key attribute" do
27
- configuration.app_key = "app_key"
28
- expect(configuration.app_key).to eq("app_key")
29
- end
30
-
31
- it "has a member token attribute" do
32
- configuration.app_secret = "app_secret"
33
- expect(configuration.app_secret).to eq("app_secret")
34
- end
35
-
36
- describe "#initialize" do
37
- it "sets key attributes provided as a hash" do
38
- configuration = Tacokit::Configuration.new \
39
- app_key: "app_key",
40
- app_secret: "app_secret",
41
- oauth_token: "oauth_token",
42
- oauth_secret: "oauth_secret"
43
-
44
- expect(configuration.app_key).to eq("app_key")
45
- expect(configuration.app_secret).to eq("app_secret")
46
- expect(configuration.oauth_token).to eq("oauth_token")
47
- expect(configuration.oauth_secret).to eq("oauth_secret")
48
- end
49
- end
50
- end
@@ -1,34 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Tacokit::Middleware::RaiseError do
4
- let(:app) { Object.new }
5
- let(:env) { Faraday::Env.new }
6
- let(:middleware) { described_class.new(app) }
7
-
8
- describe "#on_complete" do
9
- it "raises 404" do
10
- env[:status] = 404
11
- expect { middleware.on_complete(env) }.to raise_error(Tacokit::Error::ResourceNotFound)
12
- end
13
-
14
- it "raises 407" do
15
- env[:status] = 407
16
- expect { middleware.on_complete(env) }.to raise_error(Tacokit::Error::ConnectionFailed)
17
- end
18
-
19
- it "raises 400" do
20
- env[:status] = 400
21
- expect { middleware.on_complete(env) }.to raise_error(Tacokit::Error::ClientError)
22
- end
23
-
24
- it "raises 401" do
25
- env[:status] = 401
26
- expect { middleware.on_complete(env) }.to raise_error(Tacokit::Error::Unauthorized)
27
- end
28
-
29
- it "does nothing" do
30
- env[:status] = 200
31
- expect { middleware.on_complete(env) }.not_to raise_error
32
- end
33
- end
34
- end
@@ -1,151 +0,0 @@
1
- require "spec_helper"
2
-
3
- module Tacokit
4
- describe Resource do
5
- describe "#initialize" do
6
- it "handles given attributes" do
7
- res = Resource.new one: "one", "two" => :two
8
-
9
- expect(res).to be_a(Resource)
10
- expect(res.one).to eq "one"
11
- expect(res.two).to eq :two
12
- end
13
-
14
- it "handles nested objects" do
15
- res = Resource.new prefs: { user: { read: "ftw" } }
16
-
17
- expect(res.prefs.user.read).to eq "ftw"
18
- expect(res.prefs).to be_a(Resource)
19
- expect(res.prefs.user).to be_a(Resource)
20
- end
21
-
22
- it "has nested collections" do
23
- res = Resource.new labels: [{ color: "blue" }]
24
-
25
- expect(res.labels.size).to eq 1
26
-
27
- label = res.labels.first
28
- expect(label.color).to eq "blue"
29
- expect(label).to be_a(Resource)
30
- end
31
-
32
- it "handles clashing keys" do
33
- res = Resource.new client: 1, fields: 2
34
-
35
- expect(res.fields).to eq 2
36
-
37
- expect(res._fields).to include(:fields)
38
- expect(res._fields.size).to eq(2)
39
- end
40
-
41
- it "has attribute predicates" do
42
- res = Resource.new a: 1, b: true, c: nil, d: false
43
-
44
- expect(res.a?).to be_truthy
45
- expect(res.b?).to be_truthy
46
- expect(res.c?).to be_falsey
47
- expect(res.d?).to be_falsey
48
- end
49
-
50
- it "has attribute setters" do
51
- res = Resource.new a: 1
52
-
53
- expect(res.a).to eq 1
54
- expect(res.key?(:a)).to be_truthy
55
-
56
- res.b = 2
57
- expect(res.b).to eq 2
58
- expect(res.key?(:b)).to be_truthy
59
- end
60
-
61
- it "dynamically adds attr methods through getters" do
62
- res = Resource.new
63
-
64
- expect(res.respond_to?(:a)).to be_falsey
65
- expect(res.respond_to?(:a=)).to be_falsey
66
- expect(res.respond_to?(:a?)).to be_falsey
67
-
68
- res = Resource.new a: 1
69
- expect(res.respond_to?(:a)).to be_truthy
70
- expect(res.respond_to?(:a=)).to be_truthy
71
- expect(res.respond_to?(:a?)).to be_truthy
72
- end
73
-
74
- it "has nillable attribute getters" do
75
- res = Resource.new a: 1
76
-
77
- expect(res.key?(:b)).to be_falsey
78
- expect(res.respond_to?(:b)).to be_falsey
79
- expect(res.respond_to?(:b=)).to be_falsey
80
- expect(res.respond_to?(:b?)).to be_falsey
81
- expect(res.b).to be_nil
82
- expect { res.b }.not_to raise_error
83
- end
84
-
85
- it "dynamically adds attr methods through setters" do
86
- res = Resource.new a: 1
87
-
88
- expect(res.key?(:b)).to be_falsey
89
- expect(res.respond_to?(:b)).to be_falsey
90
- expect(res.respond_to?(:b=)).to be_falsey
91
- expect(res.respond_to?(:b?)).to be_falsey
92
-
93
- res.b = 1
94
-
95
- expect(res.key?(:b)).to be_truthy
96
- expect(res.respond_to?(:b)).to be_truthy
97
- expect(res.respond_to?(:b=)).to be_truthy
98
- expect(res.respond_to?(:b?)).to be_truthy
99
- end
100
-
101
- it "is enumerable" do
102
- res = Resource.new a: 1, b: 2
103
-
104
- output = []
105
- res.each { |k, v| output << [k, v] }
106
- expect(output).to eq [[:a, 1], [:b, 2]]
107
- end
108
-
109
- it "casts date timestamps" do
110
- res = Resource.new date: "2015-01-13T13:43:00.347Z"
111
-
112
- expect(res.date).to be_a(Time)
113
- end
114
-
115
- describe "#attrs" do
116
- it "returns hash of attributes" do
117
- res = Resource.new a: 1
118
-
119
- expect(res.to_attrs).to eq a: 1
120
- end
121
-
122
- it "returns nested attributes" do
123
- res = Resource.new a: 1, b: [{ c: 2 }]
124
-
125
- expect(res.b).to be_a(Array)
126
- expect(res.b.first).to be_a(Resource)
127
-
128
- expect(res.to_attrs).to eq(a: 1, b: [{ c: 2 }])
129
- end
130
-
131
- it "responds to [] and []=" do
132
- res = Resource.new a: 1
133
-
134
- expect(res.a).to eq 1
135
- expect(res[:a]).to eq 1
136
- expect(res["a"]).to eq 1
137
-
138
- res[:a] = 2
139
- expect(res.a).to eq 2
140
- expect(res[:a]).to eq 2
141
- expect(res["a"]).to eq 2
142
-
143
- res["a"] = 3
144
- expect(res.a).to eq 3
145
- expect(res[:a]).to eq 3
146
- expect(res["a"]).to eq 3
147
- end
148
- end
149
- end
150
- end
151
- end