chute 0.0.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/Gemfile +16 -2
  2. data/Gemfile.lock +52 -0
  3. data/LICENSE.txt +20 -0
  4. data/README.md +46 -0
  5. data/Rakefile +48 -6
  6. data/VERSION +1 -0
  7. data/chute.gemspec +120 -16
  8. data/lib/chute.rb +7 -20
  9. data/lib/chute/client.rb +42 -0
  10. data/lib/chute/configuration.rb +40 -0
  11. data/lib/chute/connection.rb +64 -0
  12. data/lib/chute/response.rb +22 -0
  13. data/lib/chute/v2/albums.rb +60 -0
  14. data/lib/chute/v2/assets.rb +55 -0
  15. data/lib/chute/v2/comments.rb +29 -0
  16. data/lib/chute/v2/flags.rb +21 -0
  17. data/lib/chute/v2/hearts.rb +21 -0
  18. data/lib/chute/v2/parcels.rb +21 -0
  19. data/lib/chute/v2/tags.rb +36 -0
  20. data/lib/chute/v2/triggers.rb +26 -0
  21. data/lib/chute/v2/users.rb +18 -0
  22. data/lib/chute/v2/votes.rb +21 -0
  23. data/lib/chute/version.rb +7 -1
  24. data/spec/chute/chute_spec.rb +64 -0
  25. data/spec/chute/client_spec.rb +82 -0
  26. data/spec/chute/connection_spec.rb +47 -0
  27. data/spec/chute/response_spec.rb +16 -0
  28. data/spec/chute/v2/albums_spec.rb +197 -0
  29. data/spec/chute/v2/assets_spec.rb +171 -0
  30. data/spec/chute/v2/comments_spec.rb +88 -0
  31. data/spec/chute/v2/flags_spec.rb +56 -0
  32. data/spec/chute/v2/hearts_spec.rb +57 -0
  33. data/spec/chute/v2/parcels_spec.rb +24 -0
  34. data/spec/chute/v2/tags_spec.rb +79 -0
  35. data/spec/chute/v2/trigger_spec.rb +127 -0
  36. data/spec/chute/v2/users_spec.rb +53 -0
  37. data/spec/chute/v2/votes_spec.rb +56 -0
  38. data/spec/fixtures/chute_cassettes/albums/album_create_with_permission_view.yml +69 -0
  39. data/spec/fixtures/chute_cassettes/albums/albums_add_remove_assets.yml +187 -0
  40. data/spec/fixtures/chute_cassettes/albums/albums_create.yml +69 -0
  41. data/spec/fixtures/chute_cassettes/albums/albums_delete.yml +128 -0
  42. data/spec/fixtures/chute_cassettes/albums/albums_get.yml +135 -0
  43. data/spec/fixtures/chute_cassettes/albums/albums_list.yml +89 -0
  44. data/spec/fixtures/chute_cassettes/albums/albums_stats.yml +128 -0
  45. data/spec/fixtures/chute_cassettes/albums/albums_update.yml +135 -0
  46. data/spec/fixtures/chute_cassettes/assets/assets_delete.yml +131 -0
  47. data/spec/fixtures/chute_cassettes/assets/assets_geo.yml +197 -0
  48. data/spec/fixtures/chute_cassettes/assets/assets_get.yml +138 -0
  49. data/spec/fixtures/chute_cassettes/assets/assets_import.yml +76 -0
  50. data/spec/fixtures/chute_cassettes/assets/assets_list.yml +77 -0
  51. data/spec/fixtures/chute_cassettes/assets/assets_update.yml +138 -0
  52. data/spec/fixtures/chute_cassettes/comments/comments_create.yml +196 -0
  53. data/spec/fixtures/chute_cassettes/comments/comments_list.yml +259 -0
  54. data/spec/fixtures/chute_cassettes/flags/flags_methods.yml +313 -0
  55. data/spec/fixtures/chute_cassettes/hearts/hearts_methods.yml +254 -0
  56. data/spec/fixtures/chute_cassettes/tags/tags_assets.yml +311 -0
  57. data/spec/fixtures/chute_cassettes/triggers/trigger_errors.yml +62 -0
  58. data/spec/fixtures/chute_cassettes/triggers/triggers_cleanup.yml +184 -0
  59. data/spec/fixtures/chute_cassettes/triggers/triggers_create.yml +65 -0
  60. data/spec/fixtures/chute_cassettes/triggers/triggers_delete.yml +124 -0
  61. data/spec/fixtures/chute_cassettes/triggers/triggers_list.yml +66 -0
  62. data/spec/fixtures/chute_cassettes/triggers/triggers_update.yml +127 -0
  63. data/spec/fixtures/chute_cassettes/users/users_get.yml +128 -0
  64. data/spec/fixtures/chute_cassettes/users/users_me.yml +66 -0
  65. data/spec/fixtures/chute_cassettes/votes/votes_methods.yml +313 -0
  66. data/spec/spec_helper.rb +27 -0
  67. metadata +210 -33
  68. data/.gitignore +0 -5
  69. data/README +0 -125
  70. data/config/chute.rb +0 -0
  71. data/lib/chute/account.rb +0 -58
  72. data/lib/chute/app.rb +0 -32
  73. data/lib/chute/asset.rb +0 -124
  74. data/lib/chute/bundle.rb +0 -72
  75. data/lib/chute/chute.rb +0 -203
  76. data/lib/chute/collection.rb +0 -47
  77. data/lib/chute/comment.rb +0 -32
  78. data/lib/chute/exception.rb +0 -7
  79. data/lib/chute/http_service.rb +0 -114
  80. data/lib/chute/inbox.rb +0 -41
  81. data/lib/chute/parcel.rb +0 -45
  82. data/lib/chute/resource.rb +0 -354
  83. data/lib/chute/user.rb +0 -113
  84. data/lib/chute/util.rb +0 -14
  85. data/test/test_sudoku.rb +0 -7
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chute::Client do
4
+
5
+ before do
6
+ @keys = Chute::Configuration::VALID_CONFIG_KEYS
7
+ end
8
+
9
+ describe 'with module configuration' do
10
+ before do
11
+ Chute.configure do |config|
12
+ @keys.each do |key|
13
+ config.send("#{key}=", key)
14
+ end
15
+ end
16
+ end
17
+
18
+ after do
19
+ Chute.reset
20
+ end
21
+
22
+ it "should inherit module configuration" do
23
+ api = Chute::Client.new
24
+ @keys.each do |key|
25
+ api.send(key).should == key
26
+ end
27
+ end
28
+
29
+ describe 'with class configuration' do
30
+ before do
31
+ @config = {
32
+ :api_endpoint => 'api',
33
+ :auth_endpoint => 'auth',
34
+ :app_id => 'id',
35
+ :app_secret => 'secret',
36
+ :access_token => 'token',
37
+ }
38
+ end
39
+
40
+ it 'should override module configuration' do
41
+ api = Chute::Client.new(@config)
42
+ @keys.each do |key|
43
+ api.send(key).should == @config[key]
44
+ end
45
+ end
46
+
47
+ it 'should override module configuration after' do
48
+ api = Chute::Client.new
49
+
50
+ @config.each do |key, value|
51
+ api.send("#{key}=", value)
52
+ end
53
+
54
+ @keys.each do |key|
55
+ api.send("#{key}").should == @config[key]
56
+ end
57
+ end
58
+
59
+ end
60
+
61
+ end
62
+
63
+ describe '#as' do
64
+ it 'should set the token for the duration of the block' do
65
+ Chute.as 'abc' do
66
+ Chute.access_token.should == 'abc'
67
+ end
68
+ Chute.access_token.should_not == 'abc'
69
+ end
70
+ end
71
+
72
+ describe "client request methods" do
73
+
74
+ [:get, :post, :put, :delete].each do |req_type|
75
+ it "should have #{req_type} method defined" do
76
+ Chute::Client.should respond_to req_type
77
+ end
78
+ end
79
+
80
+ end
81
+
82
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chute::Connection do
4
+ describe "methods" do
5
+ it "must include httparty methods" do
6
+ Chute::Connection.should include HTTParty
7
+ end
8
+ it "must have the base url set to the Chute API endpoint" do
9
+ Chute::Connection.base_uri.should == Chute.api_endpoint
10
+ end
11
+
12
+ describe ".request" do
13
+ it { Chute::Connection.should respond_to(:request).with(2).arguments }
14
+ it { Chute::Connection.should respond_to(:request).with(3).arguments }
15
+ it { Chute::Connection.should_not respond_to(:request).with(0).arguments}
16
+ end
17
+
18
+ end
19
+
20
+ describe "headers" do
21
+
22
+ it "must have the Authorization header" do
23
+ Chute::Connection.headers.has_key?("Authorization").should == true
24
+ end
25
+
26
+ it "must have Authorization set to Access Token value" do
27
+ Chute::Connection.headers["Authorization"].should == "OAuth #{Chute.access_token}"
28
+ end
29
+
30
+ it "must have the Content-Type header" do
31
+ Chute::Connection.headers.has_key?("Content-Type").should == true
32
+ end
33
+
34
+ it "must have the Accepts header" do
35
+ Chute::Connection.headers.has_key?("Accepts").should == true
36
+ end
37
+
38
+ ["Content-Type", "Accepts"].each do |key|
39
+ it "must have header #{key} set to application/json" do
40
+ Chute::Connection.headers[key].should == "application/json"
41
+ end
42
+ end
43
+
44
+ end
45
+
46
+
47
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chute::Response do
4
+
5
+ it { Chute::Response.should respond_to(:with_code_and_error).with(2).arguments }
6
+ it { Chute::Response.new.should respond_to(:success?).with(0).arguments }
7
+ it { Chute::Response.new.should respond_to(:pretty_print).with(0).arguments }
8
+
9
+ context '#with_code_and_error' do
10
+ it 'should work' do
11
+ obj = Chute::Response.with_code_and_error(500, 'broke')
12
+ obj.inspect
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,197 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chute::V2::Albums do
4
+ include_context "init credentials"
5
+
6
+
7
+ describe "methods" do
8
+
9
+ describe ".all" do
10
+ it { Chute::V2::Albums.should respond_to(:all).with(0).arguments }
11
+ it { Chute::V2::Albums.should respond_to(:all).with(1).arguments }
12
+ it { Chute::V2::Albums.should respond_to(:all).with(2).arguments }
13
+ end
14
+
15
+ describe ".find" do
16
+ it { Chute::V2::Albums.should respond_to(:find).with(1).arguments }
17
+ it { Chute::V2::Albums.should_not respond_to(:find).with(0).arguments }
18
+ end
19
+
20
+ describe ".geo_locate" do
21
+ it { Chute::V2::Albums.should respond_to(:geo_locate).with(4).arguments }
22
+ it { Chute::V2::Albums.should_not respond_to(:geo_locate).with(5).arguments }
23
+ end
24
+
25
+ describe ".assets" do
26
+ it { Chute::V2::Albums.should respond_to(:assets).with(3).arguments }
27
+ it { Chute::V2::Albums.should_not respond_to(:assets).with(4).arguments }
28
+ end
29
+
30
+ describe ".import" do
31
+ it { Chute::V2::Albums.should respond_to(:import).with(2).arguments }
32
+ it { Chute::V2::Albums.should_not respond_to(:import).with(0).arguments }
33
+ end
34
+
35
+ describe ".create" do
36
+ it { Chute::V2::Albums.should respond_to(:create).with(1).arguments }
37
+ it { Chute::V2::Albums.should_not respond_to(:create).with(2).arguments }
38
+ end
39
+
40
+ describe ".update" do
41
+ it { Chute::V2::Albums.should respond_to(:update).with(2).arguments }
42
+ it { Chute::V2::Albums.should_not respond_to(:update).with(0).arguments }
43
+ end
44
+
45
+ describe ".delete" do
46
+ it { Chute::V2::Albums.should respond_to(:delete).with(1).arguments }
47
+ it { Chute::V2::Albums.should_not respond_to(:delete).with(2).arguments }
48
+ end
49
+
50
+ describe ".stats" do
51
+ it { Chute::V2::Albums.should respond_to(:stats).with(1).arguments }
52
+ it { Chute::V2::Albums.should_not respond_to(:stats).with(0).arguments }
53
+ end
54
+
55
+ describe ".add_assets" do
56
+ it { Chute::V2::Albums.should respond_to(:add_assets).with(2).arguments }
57
+ it { Chute::V2::Albums.should_not respond_to(:add_assets).with(0).arguments }
58
+ end
59
+ describe ".remove_assets" do
60
+ it { Chute::V2::Albums.should respond_to(:remove_assets).with(2).arguments }
61
+ it { Chute::V2::Albums.should_not respond_to(:remove_assets).with(0).arguments }
62
+ end
63
+
64
+ end
65
+
66
+ describe "requests" do
67
+ describe "GET Album List" do
68
+ before do
69
+ VCR.insert_cassette 'albums/albums_list', :record => :new_episodes
70
+ end
71
+ after do
72
+ VCR.eject_cassette
73
+ end
74
+
75
+ it "should be able to list all albums" do
76
+ response = Chute::V2::Albums.all
77
+ response.data.should_not == nil
78
+
79
+ end
80
+
81
+ it "should contain pagination" do
82
+ response = Chute::V2::Albums.all
83
+ response.pagination.should_not ==nil
84
+ end
85
+
86
+ end
87
+
88
+ describe "POST Album Create" do
89
+ it "should be able to create an album" do
90
+ VCR.insert_cassette 'albums/albums_create', :record => :new_episodes
91
+ album = Hash.new
92
+ album[:name] = "some album #{Time.now.to_s}"
93
+ album[:moderate_comments] = true
94
+ response = Chute::V2::Albums.create(album)
95
+ VCR.eject_cassette
96
+ end
97
+
98
+ it 'should respect permission_view' do
99
+ VCR.insert_cassette 'albums/album_create_with_permission_view', :record => :new_episodes
100
+ album = Hash.new
101
+ album[:name] = "some new album #{Time.now.to_s}"
102
+ album[:permission_view] = 2
103
+ response = Chute::V2::Albums.create(album)
104
+ VCR.eject_cassette
105
+ end
106
+ end
107
+
108
+ describe "GET Album by ID" do
109
+ before do
110
+ VCR.insert_cassette 'albums/albums_get', :record => :new_episodes
111
+ end
112
+ after do
113
+ VCR.eject_cassette
114
+ end
115
+
116
+ it "should retrieve album by its id" do
117
+ id = Chute::V2::Albums.create({:name => "Created Album"}).data.id
118
+ response = Chute::V2::Albums.find(id)
119
+ response.data.id.should == id
120
+ end
121
+ end
122
+
123
+ describe "PUT Album Update" do
124
+
125
+ before do
126
+ VCR.insert_cassette 'albums/albums_update', :record => :new_episodes
127
+ end
128
+ after do
129
+ VCR.eject_cassette
130
+ end
131
+
132
+ it "should be able to update an album" do
133
+ response = Chute::V2::Albums.create({:name => "Created Album"})
134
+ name = "Updated Album"
135
+ response = Chute::V2::Albums.update(response.data.id, {:name => name})
136
+ response.data.name.should == name
137
+ end
138
+ end
139
+
140
+ describe "DELETE Album" do
141
+
142
+ before do
143
+ VCR.insert_cassette 'albums/albums_delete', :record => :new_episodes
144
+ end
145
+ after do
146
+ VCR.eject_cassette
147
+ end
148
+
149
+ it "should be able to delete an album" do
150
+ response = Chute::V2::Albums.create({:name => "Created Album"})
151
+ response = Chute::V2::Albums.delete(response.data.id)
152
+ response.success?.should == true
153
+ end
154
+ end
155
+
156
+ describe "GET Album Stats" do
157
+ before do
158
+ VCR.insert_cassette 'albums/albums_stats', :record => :new_episodes
159
+ end
160
+ after do
161
+ VCR.eject_cassette
162
+ end
163
+
164
+ it "should retrieve stats" do
165
+ response = Chute::V2::Albums.create({:name => "Created Album"})
166
+ response = Chute::V2::Albums.stats(response.data.id)
167
+ end
168
+ end
169
+
170
+ describe "POST add and remove Assets" do
171
+
172
+ let(:id) { Chute::V2::Albums.create({:name => "Created Album"}).data.id }
173
+ let(:asset_ids) { [4342325, 4342324, 534543] } # Non Existing assets (random)
174
+
175
+ before do
176
+ VCR.insert_cassette 'albums/albums_add_remove_assets', :record => :new_episodes
177
+ end
178
+ after do
179
+ VCR.eject_cassette
180
+ end
181
+
182
+ it "should be able to add existing assets to existing album" do
183
+ response = Chute::V2::Albums.add_assets(id, [71907823])
184
+ response.should be_true
185
+ end
186
+
187
+
188
+ it "should be able to remove existing assets from existing album" do
189
+ response = Chute::V2::Albums.remove_assets(id, asset_ids)
190
+ response.should be_true
191
+ end
192
+
193
+ end
194
+
195
+ end
196
+
197
+ end
@@ -0,0 +1,171 @@
1
+ require 'spec_helper'
2
+ # -*- coding: utf-8 -*-
3
+
4
+ describe Chute::V2::Assets do
5
+ include_context "init credentials"
6
+
7
+ describe "methods" do
8
+
9
+ describe ".all" do
10
+ it { Chute::V2::Assets.should respond_to(:all).with(1).arguments }
11
+ it { Chute::V2::Assets.should_not respond_to(:all).with(0).arguments }
12
+ end
13
+
14
+ describe ".find" do
15
+ it { Chute::V2::Assets.should respond_to(:find).with(1).arguments }
16
+ it { Chute::V2::Assets.should_not respond_to(:find).with(0).arguments }
17
+ end
18
+
19
+ describe ".geo_locate" do
20
+ it { Chute::V2::Assets.should respond_to(:geo_locate).with(3).arguments }
21
+ it { Chute::V2::Assets.should_not respond_to(:geo_locate).with(4).arguments }
22
+ end
23
+
24
+ describe ".exif" do
25
+ it { Chute::V2::Assets.should respond_to(:exif).with(1).arguments }
26
+ it { Chute::V2::Assets.should_not respond_to(:exif).with(2).arguments }
27
+ end
28
+
29
+ describe ".geo" do
30
+ it { Chute::V2::Assets.should respond_to(:geo).with(1).arguments }
31
+ it { Chute::V2::Assets.should_not respond_to(:geo).with(2).arguments }
32
+ end
33
+
34
+ describe ".upload" do
35
+ pending "Not implemented yet"
36
+ it { Chute::V2::Assets.should respond_to(:upload).with(1).arguments }
37
+ it { Chute::V2::Assets.should_not respond_to(:upload).with(2).arguments }
38
+ end
39
+
40
+ describe ".update" do
41
+ it { Chute::V2::Assets.should respond_to(:update).with(2).arguments }
42
+ it { Chute::V2::Assets.should respond_to(:update).with(3).arguments }
43
+ it { Chute::V2::Assets.should_not respond_to(:update).with(0).arguments }
44
+ end
45
+
46
+ describe ".delete" do
47
+ it { Chute::V2::Assets.should respond_to(:delete).with(1).arguments }
48
+ it { Chute::V2::Assets.should_not respond_to(:delete).with(2).arguments }
49
+ end
50
+
51
+ end
52
+
53
+ describe "requests" do
54
+
55
+ before do
56
+ @asset_urls = ['http://www.wix.com/blog/wp-content/uploads/2012/08/HowToGoBeyondStockPhotoCliches.jpg',
57
+ 'http://static.guim.co.uk/sys-images/Guardian/Pix/pictures/2012/11/27/1354010019306/Brad-Pitt-010.jpg',
58
+ 'http://datastore01.rediff.com/h1500-w1500/thumb/52605E5F6D6C65665C60665C696C7371/fuugfaw7icy0hq4j.D.0.Richa-Gangopadhyay-Latest-Hot-Photo.jpg'
59
+ ]
60
+ end
61
+ let(:list_assets) { Chute::V2::Assets.all(2327121) } # Test album id
62
+
63
+ describe "GET Assets List" do
64
+ before do
65
+ VCR.insert_cassette 'assets/assets_list', :record => :new_episodes
66
+ end
67
+ after do
68
+ VCR.eject_cassette
69
+ end
70
+
71
+
72
+
73
+ it "should be able to list all assets in an album" do
74
+ response = list_assets
75
+ response.data.should_not == nil
76
+ end
77
+ end
78
+
79
+ describe "POST Asset Import" do
80
+
81
+ before do
82
+ VCR.insert_cassette 'assets/assets_import', :record => :new_episodes
83
+ end
84
+ after do
85
+ VCR.eject_cassette
86
+ end
87
+
88
+ it "should be able to import assets from urls" do
89
+ response = Chute::V2::Assets.import(@asset_urls,nil)
90
+ response.data.map { |a| @asset_urls.include?(a.source.source_url).should==true }
91
+ end
92
+
93
+ end
94
+
95
+ describe "GET Asset by ID" do
96
+ before do
97
+ VCR.insert_cassette 'assets/assets_get', :record => :new_episodes
98
+ end
99
+ after do
100
+ VCR.eject_cassette
101
+ end
102
+
103
+ it "should retrieve asset by its id" do
104
+ response = Chute::V2::Assets.import(@asset_urls[0],nil)
105
+ id = response.data[0].id
106
+ response = Chute::V2::Assets.find(id)
107
+ response.data.id.should == id
108
+ end
109
+ end
110
+
111
+ describe "PUT Asset Update" do
112
+
113
+ before do
114
+ VCR.insert_cassette 'assets/assets_update', :record => :new_episodes
115
+ end
116
+ after do
117
+ VCR.eject_cassette
118
+ end
119
+
120
+ it "should be able to update an assets title" do
121
+ response = Chute::V2::Assets.import(@asset_urls[0],nil)
122
+ caption = "New Asset Title"
123
+ response = Chute::V2::Assets.update(response.data[0].id, :caption => caption)
124
+ response.data.caption.should == caption
125
+ end
126
+ end
127
+
128
+ describe "DELETE Asset" do
129
+
130
+ before do
131
+ @asset_url = 'http://image.coloring.com/pictures/overlay/cat-and-fancy-mouse.gif'
132
+ VCR.insert_cassette 'assets/assets_delete', :record => :new_episodes
133
+ end
134
+ after do
135
+ VCR.eject_cassette
136
+ end
137
+
138
+ it "should be able to delete an asset" do
139
+ response = Chute::V2::Assets.import(@asset_url,nil)
140
+ response = Chute::V2::Assets.delete(response.data[0].id)
141
+ response.success?.should == true
142
+ end
143
+ end
144
+
145
+ describe "GET geo for asset" do
146
+
147
+ let(:import_assets) { Chute::V2::Assets.import(@asset_urls,nil) }
148
+
149
+ before do
150
+ VCR.insert_cassette 'assets/assets_geo', :record => :new_episodes
151
+ end
152
+ after do
153
+ VCR.eject_cassette
154
+ end
155
+
156
+ it "should fetch geo info for asset" do
157
+ response = import_assets
158
+ response = Chute::V2::Assets.geo(response.data[0].id)
159
+ response.data.should_not == nil
160
+ end
161
+
162
+ it "should be able to find near location with radius" do
163
+ response = import_assets
164
+ response = Chute::V2::Assets.geo_locate("-36.88155833","174.70791111", 500)
165
+ response.data.should_not == nil
166
+ end
167
+
168
+ end
169
+
170
+ end
171
+ end