croudia 1.0.12 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d4a58cfd9120736f45872cdf84debae55fb32c6
4
- data.tar.gz: d9f42d52f34058b0f2b4c20074a339149777e3e0
3
+ metadata.gz: b0347fb33dca00cf9f17791001f8ce93c8fcca18
4
+ data.tar.gz: 73a1c169329a27b582821c7b8c4ca4e006218004
5
5
  SHA512:
6
- metadata.gz: 51cacb282bfb8f3cd36ffc8d505b61f9aad40d3d0b7a621eac97c39c1eba6641d3229128e0e06158d55d8ae81a42b5751b12b3ddb4ec7b14b189c47637cb8f01
7
- data.tar.gz: 1d1ca52175317b7c7e5a5500ee78bd1636d91bc56e4789fc9565d3ed446b67a2b011918d5e9e41776e2dde7a1fa0c2799c3fbd156715a95b899f5c4e5031db05
6
+ metadata.gz: e5167ca9e3ecaa4f14fc17070e2ac568a832b1780db500926568bcec1225f737ec1595bfce16282d24d0f594b32139b5d5b6f1631312cbd56cd32e26ae92a710
7
+ data.tar.gz: 1d57c97c48f7a984f07fd43d324d887cb435ba2a7ce3c8af0348d7cc2fa530b7e43d9c64dd7d1d2249b9ccfbf2bb348e1f8e0dd5e857a39b0fc9edce8e2b00c9
@@ -1,3 +1,4 @@
1
+ require 'croudia/cursor'
1
2
  require 'croudia/relationship'
2
3
  require 'croudia/user'
3
4
 
@@ -49,6 +50,50 @@ module Croudia
49
50
  resp = get('/friendships/lookup.json', params)
50
51
  objects(Croudia::User, resp)
51
52
  end
53
+
54
+ # Friend ids of specified user
55
+ #
56
+ # @param user [String, Integer, Croudia::User]
57
+ # @param params [Hash]
58
+ # @return [Croudia::Cursor] Cursor object that contains friend ids
59
+ def friend_ids(user=current_user, params={})
60
+ merge_user!(params, user)
61
+ resp = get('/friends/ids.json', params)
62
+ Croudia::Cursor.new(:ids, nil, resp)
63
+ end
64
+
65
+ # Follower ids of specified user
66
+ #
67
+ # @param user [String, Integer, Croudia::User]
68
+ # @param params [Hash]
69
+ # @return [Croudia::Cursor]
70
+ def follower_ids(user=current_user, params={})
71
+ merge_user!(params, user)
72
+ resp = get('/followers/ids.json', params)
73
+ Croudia::Cursor.new(:ids, nil, resp)
74
+ end
75
+
76
+ # Friends of specified user
77
+ #
78
+ # @param user [String, Integer, Croudia::User]
79
+ # @param params [Hash]
80
+ # @return [Croudia::Cursor]
81
+ def friends(user=current_user, params={})
82
+ merge_user!(params, user)
83
+ resp = get('/friends/list.json', params)
84
+ Croudia::Cursor.new(:users, Croudia::User, resp)
85
+ end
86
+
87
+ # Followers of specified user
88
+ #
89
+ # @param user [String, Integer, Croudia::User]
90
+ # @param params [Hash]
91
+ # @return [Croudia::Cursor]
92
+ def followers(user=current_user, params={})
93
+ merge_user!(params, user)
94
+ resp = get('/followers/list.json', params)
95
+ Croudia::Cursor.new(:users, Croudia::User, resp)
96
+ end
52
97
  end
53
98
  end
54
99
  end
@@ -0,0 +1,30 @@
1
+ require 'croudia/base'
2
+
3
+ module Croudia
4
+ class Cursor < Croudia::Base
5
+ KEYS = [
6
+ :next_cursor,
7
+ :next_cursor_str,
8
+ :previous_cursor,
9
+ :previous_cursor_str,
10
+ ]
11
+
12
+ attr_reader(*KEYS)
13
+
14
+ def initialize(key, klass, attrs)
15
+ if klass.is_a?(Class)
16
+ attrs[key.to_s].map! { |element| klass.new(element) }
17
+ end
18
+ singleton_class.attr_reader(key)
19
+ super(attrs)
20
+ end
21
+
22
+ def first?
23
+ previous_cursor.zero?
24
+ end
25
+
26
+ def last?
27
+ next_cursor.zero?
28
+ end
29
+ end
30
+ end
@@ -1,3 +1,3 @@
1
1
  module Croudia
2
- VERSION = '1.0.12'
2
+ VERSION = '1.0.13'
3
3
  end
@@ -247,4 +247,116 @@ describe Croudia::API::Friendships do
247
247
  end
248
248
  end
249
249
  end
250
+
251
+ describe '#friend_ids' do
252
+ before do
253
+ stub_get('/friends/ids.json').with(query: {
254
+ screen_name: 'wktk',
255
+ }).to_return(
256
+ body: fixture(:ids_with_cursor),
257
+ headers: { content_type: 'application/json; charset=utf-8' }
258
+ )
259
+ end
260
+
261
+ it 'requests the correct resource' do
262
+ @client.friend_ids('wktk')
263
+ expect(a_get('/friends/ids.json').with(query: {
264
+ screen_name: 'wktk',
265
+ })).to have_been_made
266
+ end
267
+
268
+ it 'returns Croudia::Cursor' do
269
+ subject = @client.friend_ids('wktk')
270
+ expect(subject).to be_a Croudia::Cursor
271
+ end
272
+
273
+ it 'cursor responds to ids' do
274
+ subject = @client.friend_ids('wktk')
275
+ expect(subject.respond_to?(:ids)).to be_true
276
+ end
277
+ end
278
+
279
+ describe '#follower_ids' do
280
+ before do
281
+ stub_get('/followers/ids.json').with(query: {
282
+ screen_name: 'wktk',
283
+ }).to_return(
284
+ body: fixture(:ids_with_cursor),
285
+ headers: { content_type: 'application/json; charset=utf-8' }
286
+ )
287
+ end
288
+
289
+ it 'requests the correct resource' do
290
+ @client.follower_ids('wktk')
291
+ expect(a_get('/followers/ids.json').with(query: {
292
+ screen_name: 'wktk',
293
+ })).to have_been_made
294
+ end
295
+
296
+ it 'returns Croudia::Cursor' do
297
+ subject = @client.follower_ids('wktk')
298
+ expect(subject).to be_a Croudia::Cursor
299
+ end
300
+
301
+ it 'cursor responds to ids' do
302
+ subject = @client.follower_ids('wktk')
303
+ expect(subject.respond_to?(:ids)).to be_true
304
+ end
305
+ end
306
+
307
+ describe '#friends' do
308
+ before do
309
+ stub_get('/friends/list.json').with(query: {
310
+ screen_name: 'wktk',
311
+ }).to_return(
312
+ body: fixture(:users_with_cursor),
313
+ headers: { content_type: 'application/json; charset=utf-8' }
314
+ )
315
+ end
316
+
317
+ it 'requests the correct resource' do
318
+ @client.friends('wktk')
319
+ expect(a_get('/friends/list.json').with(query: {
320
+ screen_name: 'wktk',
321
+ })).to have_been_made
322
+ end
323
+
324
+ it 'returns Croudia::Cursor' do
325
+ subject = @client.friends('wktk')
326
+ expect(subject).to be_a Croudia::Cursor
327
+ end
328
+
329
+ it 'cursor responds to users' do
330
+ subject = @client.friends('wktk')
331
+ expect(subject.respond_to?(:users)).to be_true
332
+ end
333
+ end
334
+
335
+ describe '#followers' do
336
+ before do
337
+ stub_get('/followers/list.json').with(query: {
338
+ screen_name: 'wktk',
339
+ }).to_return(
340
+ body: fixture(:users_with_cursor),
341
+ headers: { content_type: 'application/json; charset=utf-8' }
342
+ )
343
+ end
344
+
345
+ it 'requests the correct resource' do
346
+ @client.followers('wktk')
347
+ expect(a_get('/followers/list.json').with(query: {
348
+ screen_name: 'wktk',
349
+ })).to have_been_made
350
+ end
351
+
352
+ it 'returns Croudia::Cursor' do
353
+ subject = @client.followers('wktk')
354
+ expect(subject).to be_a Croudia::Cursor
355
+ end
356
+
357
+ it 'cursor responds to users' do
358
+ subject = @client.followers('wktk')
359
+ expect(subject.respond_to?(:users)).to be_true
360
+ end
361
+ end
250
362
  end
@@ -0,0 +1,37 @@
1
+ require 'helper'
2
+
3
+ describe Croudia::Cursor do
4
+ it 'defines a method to access data' do
5
+ cursor = Croudia::Cursor.new(:hoge, nil, {'hoge' => 'ok'})
6
+ expect(cursor.hoge).to eq 'ok'
7
+ end
8
+
9
+ it 'converts each data into instance of given class name' do
10
+ cursor = Croudia::Cursor.new(:data, Time, {'data' => [1,2,3,4]})
11
+ cursor.data.each { |obj| expect(obj).to be_an Time }
12
+ end
13
+
14
+ describe '#first?' do
15
+ it 'returns true if previous_cursor is 0' do
16
+ cursor = Croudia::Cursor.new(:data, nil, {'previous_cursor' => 0})
17
+ expect(cursor.first?).to be_true
18
+ end
19
+
20
+ it 'returns false if previous_cursor is not 0' do
21
+ cursor = Croudia::Cursor.new(:data, nil, {'previous_cursor' => 5})
22
+ expect(cursor.first?).to be_false
23
+ end
24
+ end
25
+
26
+ describe '#last?' do
27
+ it 'returns true if next_cursor is 0' do
28
+ cursor = Croudia::Cursor.new(:data, nil, {'next_cursor' => 0})
29
+ expect(cursor.last?).to be_true
30
+ end
31
+
32
+ it 'returns false if next_cursor is not 0' do
33
+ cursor = Croudia::Cursor.new(:data, nil, {'next_cursor' => 5})
34
+ expect(cursor.last?).to be_false
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,7 @@
1
+ {
2
+ "ids": [1, 2, 3, 4, 5, 6, 7, 8, 9],
3
+ "next_cursor": 0,
4
+ "next_cursor_str": "0",
5
+ "previous_cursor": 0,
6
+ "previous_cursor_str": "0"
7
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "next_cursor": 0,
3
+ "next_cursor_str": "0",
4
+ "previous_cursor": 0,
5
+ "previous_cursor_str": "0",
6
+ "users": [
7
+ {"id":7987,"id_str":"7987","name":"wktk","screen_name":"wktk","profile_image_url_https":"https://croudia.com/testimages/download/9423","created_at":"Sun, 29 Jul 2012 19:21:21 +0900","description":"気軽に fav ります。Twitter でも @wktk です。 \r\nhttps://twitter.com/wktk\r\nhttps://github.com/wktk","favorites_count":68,"follow_request_sent":"underdevelopment","followers_count":12,"following":"underdevelopment","friends_count":11,"location":"Japan","statuses_count":26,"protected":false,"url":"http://wktk.jp/"}
8
+ ]
9
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: croudia
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.12
4
+ version: 1.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - wktk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-23 00:00:00.000000000 Z
11
+ date: 2013-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -123,6 +123,7 @@ files:
123
123
  - lib/croudia/client.rb
124
124
  - lib/croudia/configurable.rb
125
125
  - lib/croudia/creatable.rb
126
+ - lib/croudia/cursor.rb
126
127
  - lib/croudia/default.rb
127
128
  - lib/croudia/entities.rb
128
129
  - lib/croudia/entity/media.rb
@@ -149,6 +150,7 @@ files:
149
150
  - spec/croudia/api/users_spec.rb
150
151
  - spec/croudia/base_spec.rb
151
152
  - spec/croudia/client_spec.rb
153
+ - spec/croudia/cursor_spec.rb
152
154
  - spec/croudia/error_spec.rb
153
155
  - spec/croudia/identity_spec.rb
154
156
  - spec/croudia/secret_mail_spec.rb
@@ -160,6 +162,7 @@ files:
160
162
  - spec/fixtures/error.json
161
163
  - spec/fixtures/friendship.json
162
164
  - spec/fixtures/friendships.json
165
+ - spec/fixtures/ids_with_cursor.json
163
166
  - spec/fixtures/image.jpg
164
167
  - spec/fixtures/secret_mail.json
165
168
  - spec/fixtures/secret_mails.json
@@ -167,6 +170,7 @@ files:
167
170
  - spec/fixtures/timeline.json
168
171
  - spec/fixtures/user.json
169
172
  - spec/fixtures/users.json
173
+ - spec/fixtures/users_with_cursor.json
170
174
  - spec/helper.rb
171
175
  homepage: https://github.com/wktk/croudia-gem
172
176
  licenses:
@@ -203,6 +207,7 @@ test_files:
203
207
  - spec/croudia/api/users_spec.rb
204
208
  - spec/croudia/base_spec.rb
205
209
  - spec/croudia/client_spec.rb
210
+ - spec/croudia/cursor_spec.rb
206
211
  - spec/croudia/error_spec.rb
207
212
  - spec/croudia/identity_spec.rb
208
213
  - spec/croudia/secret_mail_spec.rb
@@ -214,6 +219,7 @@ test_files:
214
219
  - spec/fixtures/error.json
215
220
  - spec/fixtures/friendship.json
216
221
  - spec/fixtures/friendships.json
222
+ - spec/fixtures/ids_with_cursor.json
217
223
  - spec/fixtures/image.jpg
218
224
  - spec/fixtures/secret_mail.json
219
225
  - spec/fixtures/secret_mails.json
@@ -221,4 +227,5 @@ test_files:
221
227
  - spec/fixtures/timeline.json
222
228
  - spec/fixtures/user.json
223
229
  - spec/fixtures/users.json
230
+ - spec/fixtures/users_with_cursor.json
224
231
  - spec/helper.rb