croudia 1.0.7 → 1.0.8

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: 829f6043cf078f580465d187cfcb24785140f5a7
4
- data.tar.gz: f60b7a6930994a7198c831b8e91e3fd09c53fa59
3
+ metadata.gz: 6faf517b484c015bd638bfb3f87d03dd50058c63
4
+ data.tar.gz: 4bfa7828051298f954d02bc370c3304ed48ce1a3
5
5
  SHA512:
6
- metadata.gz: 3c8543d56c7269ac228d1b05858438fa983b71a9af53af805d7c6652e91e8798eb6219c122f9d0b9e9513f4985ad742bd9c49e920d573557b5990e7a82d193dc
7
- data.tar.gz: f8946c0371d644d984232f2775af201f171e6a5037b5b19e73269ee60daac94288c426e7967ed8b68a4aeadafc2b8e274ca6aeda19e1c89558e16b7deac5557b
6
+ metadata.gz: a032e89cc85042b633bcb00a1c62cd02e3c9240f750322fbed68ad1d7cc4dba30bbf27a530bf2654cb5c5531b5cd45e5f85b1f3d68e75669fdc239700df63796
7
+ data.tar.gz: aa7fe928f57ca1b93908a3236abf0ff7bf8087987d90140b99fbc96552cb0dc7f96397ec0e676858f6ce916cb269263aa6f200f35916e6969cebe43336fd8549
@@ -24,6 +24,17 @@ module Croudia
24
24
  resp = post('/friendships/destroy.json', params)
25
25
  Croudia::User.new(resp)
26
26
  end
27
+
28
+ # Lookup Friendships
29
+ #
30
+ # @param *users [String, Integer, Croudia::User]
31
+ # @param params [Hash]
32
+ # @return [Array<Croudia::User>]
33
+ def friendships(*args)
34
+ merge_users!(params = {}, args)
35
+ resp = get('/friendships/lookup.json', params)
36
+ objects(Croudia::User, resp)
37
+ end
27
38
  end
28
39
  end
29
40
  end
@@ -32,6 +32,30 @@ module Croudia
32
32
  params
33
33
  end
34
34
 
35
+ def merge_users!(params, users)
36
+ user_ids = []
37
+ screen_names = []
38
+
39
+ users.each do |user|
40
+ case user
41
+ when Hash
42
+ params.merge!(user)
43
+ when Integer
44
+ user_ids << user
45
+ when String
46
+ screen_names << user
47
+ when Croudia::User
48
+ user_ids << user.id_str
49
+ else
50
+ raise ArgumentError, 'invalid user'
51
+ end
52
+ end
53
+
54
+ params[:user_id] = user_ids.join(',') unless user_ids.empty?
55
+ params[:screen_name] = screen_names.join(',') unless screen_names.empty?
56
+ params
57
+ end
58
+
35
59
  def merge_text!(params, text, key=:status)
36
60
  case text
37
61
  when Hash
data/lib/croudia/user.rb CHANGED
@@ -7,6 +7,7 @@ module Croudia
7
7
 
8
8
  KEYS = [
9
9
  :id_str,
10
+ :connections,
10
11
  :description,
11
12
  :favorites_count,
12
13
  :follow_request_sent,
@@ -1,3 +1,3 @@
1
1
  module Croudia
2
- VERSION = '1.0.7'
2
+ VERSION = '1.0.8'
3
3
  end
@@ -84,4 +84,124 @@ describe Croudia::API::Friendships do
84
84
  expect(@client.unfollow('wktk')).to be_a Croudia::User
85
85
  end
86
86
  end
87
+
88
+ describe '#friendships' do
89
+ context 'when String is passed' do
90
+ before do
91
+ stub_get('/friendships/lookup.json').with(
92
+ query: {
93
+ screen_name: 'wktk',
94
+ }
95
+ ).to_return(
96
+ body: fixture(:friendships),
97
+ headers: { content_type: 'application/json; charset=utf-8' }
98
+ )
99
+ end
100
+
101
+ it 'requests the correct resource' do
102
+ @client.friendships('wktk')
103
+ expect(a_get('/friendships/lookup.json').with(
104
+ query: {
105
+ screen_name: 'wktk',
106
+ }
107
+ )).to have_been_made
108
+ end
109
+
110
+ it 'returns array of Croudia::User' do
111
+ subject = @client.friendships('wktk')
112
+ expect(subject).to be_an Array
113
+ subject.each { |u| expect(u).to be_a Croudia::User }
114
+ end
115
+ end
116
+
117
+ context 'when Integer is passed' do
118
+ before do
119
+ stub_get('/friendships/lookup.json').with(
120
+ query: {
121
+ user_id: '1234',
122
+ }
123
+ ).to_return(
124
+ body: fixture(:friendships),
125
+ headers: { content_type: 'application/json; charset=utf-8' }
126
+ )
127
+ end
128
+
129
+ it 'requests the correct resource' do
130
+ @client.friendships(1234)
131
+ expect(a_get('/friendships/lookup.json').with(
132
+ query: {
133
+ user_id: '1234',
134
+ }
135
+ )).to have_been_made
136
+ end
137
+ end
138
+
139
+ context 'when multiple Strings are passed' do
140
+ before do
141
+ stub_get('/friendships/lookup.json').with(
142
+ query: {
143
+ screen_name: 'wktk,croudia',
144
+ }
145
+ ).to_return(
146
+ body: fixture(:friendships),
147
+ headers: { content_type: 'application/json; charset=utf-8' }
148
+ )
149
+ end
150
+
151
+ it 'requests the correct resource' do
152
+ @client.friendships('wktk', 'croudia')
153
+ expect(a_get('/friendships/lookup.json').with(
154
+ query: {
155
+ screen_name: 'wktk,croudia',
156
+ }
157
+ )).to have_been_made
158
+ end
159
+ end
160
+
161
+ context 'when multiple Integers are passed' do
162
+ before do
163
+ stub_get('/friendships/lookup.json').with(
164
+ query: {
165
+ user_id: '1234,4567',
166
+ }
167
+ ).to_return(
168
+ body: fixture(:friendships),
169
+ headers: { content_type: 'application/json; charset=utf-8' }
170
+ )
171
+ end
172
+
173
+ it 'requests the correct resource' do
174
+ @client.friendships(1234, 4567)
175
+ expect(a_get('/friendships/lookup.json').with(
176
+ query: {
177
+ user_id: '1234,4567',
178
+ }
179
+ )).to have_been_made
180
+ end
181
+ end
182
+
183
+ context 'when multiple String and Integer are passed' do
184
+ before do
185
+ stub_get('/friendships/lookup.json').with(
186
+ query: {
187
+ user_id: '1234,4567',
188
+ screen_name: 'wktk,croudia',
189
+ }
190
+ ).to_return(
191
+ body: fixture(:friendships),
192
+ headers: { content_type: 'application/json; charset=utf-8' }
193
+ )
194
+ end
195
+
196
+ it 'requests the correct resource' do
197
+ @client.friendships('wktk', 1234, 'croudia', 4567)
198
+ expect(a_get('/friendships/lookup.json').with(
199
+ query: {
200
+ screen_name: 'wktk,croudia',
201
+ user_id: '1234,4567',
202
+ }
203
+ )).to have_been_made
204
+ end
205
+ end
206
+ end
87
207
  end
@@ -0,0 +1,16 @@
1
+ [
2
+ {
3
+ "connections": ["none"],
4
+ "id": 2,
5
+ "id_str": "2",
6
+ "name": "Croudia",
7
+ "screen_name": "croudia"
8
+ },
9
+ {
10
+ "connections": ["following", "followed-by"],
11
+ "id": 1,
12
+ "id_str": "1",
13
+ "name": "Pokemishi",
14
+ "screen_name": "pokemishi"
15
+ }
16
+ ]
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.7
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - wktk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-23 00:00:00.000000000 Z
11
+ date: 2013-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -148,6 +148,7 @@ files:
148
148
  - spec/croudia/user_spec.rb
149
149
  - spec/croudia_spec.rb
150
150
  - spec/fixtures/access_token.json
151
+ - spec/fixtures/friendships.json
151
152
  - spec/fixtures/secret_mail.json
152
153
  - spec/fixtures/secret_mails.json
153
154
  - spec/fixtures/status.json
@@ -196,6 +197,7 @@ test_files:
196
197
  - spec/croudia/user_spec.rb
197
198
  - spec/croudia_spec.rb
198
199
  - spec/fixtures/access_token.json
200
+ - spec/fixtures/friendships.json
199
201
  - spec/fixtures/secret_mail.json
200
202
  - spec/fixtures/secret_mails.json
201
203
  - spec/fixtures/status.json