croudia 1.0.0 → 1.0.1
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 +4 -4
- data/README.md +8 -2
- data/croudia.gemspec +1 -1
- data/lib/croudia/access_token.rb +12 -0
- data/lib/croudia/api/account.rb +17 -0
- data/lib/croudia/api/oauth.rb +4 -1
- data/lib/croudia/api/statuses.rb +16 -0
- data/lib/croudia/base.rb +2 -2
- data/lib/croudia/client.rb +2 -0
- data/lib/croudia/creatable.rb +1 -1
- data/lib/croudia/default.rb +0 -1
- data/lib/croudia/identity.rb +3 -3
- data/lib/croudia/status.rb +7 -7
- data/lib/croudia/version.rb +1 -1
- data/spec/croudia/api/account_spec.rb +21 -0
- data/spec/croudia/api/oauth_spec.rb +10 -0
- data/spec/croudia/api/statuses_spec.rb +14 -0
- data/spec/croudia/base_spec.rb +2 -2
- data/spec/croudia/identity_spec.rb +7 -7
- data/spec/croudia/status_spec.rb +7 -7
- data/spec/croudia/user_spec.rb +7 -7
- data/spec/fixtures/user.json +1 -0
- metadata +10 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c980e95cf02f420c143e76e15a2aa2dc0e850ce6
|
4
|
+
data.tar.gz: f654ad400d4ac8195127f94ee359477ebb503d4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc7a71258db70b68d07bed0ae5a5114862edf1717fffa66740aa7f97d2a8eaedca24f5cb21ba0d37e0dfd84041151c9e3abd3129b7f1dfa6fc1c4cc7469f8a9a
|
7
|
+
data.tar.gz: e5ab68cb788c8412aaab28e94da5f8ed18ac16560dd2e726b1c1775f23c5e99281ee6b4b1fea7d0e2d35df96133e1a7b3babf277e79d583df98f57c452147a8c
|
data/README.md
CHANGED
@@ -32,12 +32,18 @@ croudia = Croudia::Client.new(
|
|
32
32
|
# Get URL
|
33
33
|
url = croudia.authorize_url
|
34
34
|
|
35
|
-
# Or add
|
36
|
-
url = croudia.authrorize_url(
|
35
|
+
# Or add state query in URL
|
36
|
+
url = croudia.authrorize_url(state: "state_value")
|
37
37
|
|
38
38
|
# Retrieve an access token
|
39
39
|
access_token = croudia.get_access_token("code param returned by user")
|
40
40
|
#=> { "access_token" => " ... ", "refresh_token" => " ... ", ... }
|
41
|
+
|
42
|
+
# Refresh an access token
|
43
|
+
new_access_token = croudia.get_access_token(
|
44
|
+
grant_type: :refresh_token,
|
45
|
+
refresh_token: "refresh_token"
|
46
|
+
)
|
41
47
|
```
|
42
48
|
|
43
49
|
### Using the API
|
data/croudia.gemspec
CHANGED
@@ -7,6 +7,7 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.description = 'Ruby Wrapper for the Croudia API'
|
8
8
|
gem.summary = 'Croudia API'
|
9
9
|
gem.homepage = 'https://github.com/wktk/croudia-gem'
|
10
|
+
gem.license = 'MIT'
|
10
11
|
|
11
12
|
gem.files = `git ls-files`.split($\)
|
12
13
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -17,7 +18,6 @@ Gem::Specification.new do |gem|
|
|
17
18
|
|
18
19
|
gem.add_dependency 'faraday', '~> 0.8.7'
|
19
20
|
gem.add_dependency 'faraday_middleware', '~> 0.9.0'
|
20
|
-
gem.add_dependency 'hashie', '~> 2.0.5'
|
21
21
|
gem.add_development_dependency 'rake', '~> 10.1.0'
|
22
22
|
gem.add_development_dependency 'rdoc', '~> 4.0.1'
|
23
23
|
gem.add_development_dependency 'rspec', '~> 2.14.0'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'croudia/user'
|
2
|
+
|
3
|
+
module Croudia
|
4
|
+
module API
|
5
|
+
module Account
|
6
|
+
# Retrieve the Authenticated User
|
7
|
+
#
|
8
|
+
# @params params [Hash] Additional params
|
9
|
+
# @return [Croudia::User] Current user's object
|
10
|
+
def verify_credentials(params={})
|
11
|
+
resp = get('/account/verify_credentials.json', params)
|
12
|
+
Croudia::User.new(resp)
|
13
|
+
end
|
14
|
+
alias current_user verify_credentials
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/croudia/api/oauth.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'croudia/access_token'
|
2
|
+
|
1
3
|
module Croudia
|
2
4
|
module API
|
3
5
|
module OAuth
|
@@ -25,7 +27,8 @@ module Croudia
|
|
25
27
|
params[:client_id] ||= @client_id
|
26
28
|
params[:client_secret] ||= @client_secret
|
27
29
|
params[:grant_type] ||= 'authorization_code'
|
28
|
-
post('/oauth/token', params)
|
30
|
+
resp = post('/oauth/token', params)
|
31
|
+
Croudia::AccessToken.new(resp)
|
29
32
|
end
|
30
33
|
end
|
31
34
|
end
|
data/lib/croudia/api/statuses.rb
CHANGED
@@ -50,6 +50,22 @@ module Croudia
|
|
50
50
|
resp = get("/statuses/show/#{status_id}.json", params)
|
51
51
|
Croudia::Status.new(resp)
|
52
52
|
end
|
53
|
+
|
54
|
+
# Spread a status
|
55
|
+
#
|
56
|
+
# @param status_id [String, Integer, Croudia::Status] Status to spread
|
57
|
+
# @param params [Hash]
|
58
|
+
# @return [Croudia::Status] My status including spreaded status
|
59
|
+
def spread(status_id, params={})
|
60
|
+
case status_id
|
61
|
+
when String, Integer
|
62
|
+
when Croudia::Status
|
63
|
+
status_id = status_id.id_str
|
64
|
+
end
|
65
|
+
|
66
|
+
resp = post("/statuses/spread/#{status_id}.json", params)
|
67
|
+
Croudia::Status.new(resp)
|
68
|
+
end
|
53
69
|
end
|
54
70
|
end
|
55
71
|
end
|
data/lib/croudia/base.rb
CHANGED
@@ -5,10 +5,10 @@ module Croudia
|
|
5
5
|
mod = Module.new do
|
6
6
|
attrs.each do |attr|
|
7
7
|
define_method(attr) do
|
8
|
-
@attrs[attr.to_sym]
|
8
|
+
@attrs[attr.to_s] || @attrs[attr.to_sym]
|
9
9
|
end
|
10
10
|
define_method("#{attr}?") do
|
11
|
-
|
11
|
+
!!(@attrs[attr.to_s] || @attrs[attr.to_sym])
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
data/lib/croudia/client.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'croudia/api/account'
|
1
2
|
require 'croudia/api/favorites'
|
2
3
|
require 'croudia/api/oauth'
|
3
4
|
require 'croudia/api/statuses'
|
@@ -9,6 +10,7 @@ require 'faraday'
|
|
9
10
|
|
10
11
|
module Croudia
|
11
12
|
class Client
|
13
|
+
include Croudia::API::Account
|
12
14
|
include Croudia::API::Favorites
|
13
15
|
include Croudia::API::OAuth
|
14
16
|
include Croudia::API::Statuses
|
data/lib/croudia/creatable.rb
CHANGED
data/lib/croudia/default.rb
CHANGED
data/lib/croudia/identity.rb
CHANGED
@@ -4,8 +4,8 @@ module Croudia
|
|
4
4
|
class Identity < Croudia::Base
|
5
5
|
def initialize(*)
|
6
6
|
super
|
7
|
-
raise ArgumentError, 'argument must have an
|
8
|
-
@attrs[
|
7
|
+
raise ArgumentError, 'argument must have an "id" key' unless id
|
8
|
+
@attrs['id_str'] ||= id.to_s
|
9
9
|
end
|
10
10
|
|
11
11
|
# @param other [Croudia::Identity]
|
@@ -16,7 +16,7 @@ module Croudia
|
|
16
16
|
|
17
17
|
# @return [Integer]
|
18
18
|
def id
|
19
|
-
@attrs[:id]
|
19
|
+
@attrs['id'] || @attrs[:id]
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
data/lib/croudia/status.rb
CHANGED
@@ -14,13 +14,13 @@ module Croudia
|
|
14
14
|
:text, :user
|
15
15
|
|
16
16
|
def initialize(attrs={})
|
17
|
-
user = attrs.delete(
|
18
|
-
pss = attrs.delete(
|
19
|
-
reply_status = attrs.delete(
|
17
|
+
user = attrs.delete('user')
|
18
|
+
pss = attrs.delete('play_spread_status')
|
19
|
+
reply_status = attrs.delete('reply_status')
|
20
20
|
super(attrs)
|
21
|
-
@attrs[
|
22
|
-
@attrs[
|
23
|
-
@attrs[
|
21
|
+
@attrs['user'] = Croudia::User.new(user) if user
|
22
|
+
@attrs['play_spread_status'] = Croudia::Status.new(pss) if pss
|
23
|
+
@attrs['reply_status'] = Croudia::Status.new(reply_status) if reply_status
|
24
24
|
end
|
25
25
|
end
|
26
|
-
end
|
26
|
+
end
|
data/lib/croudia/version.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Croudia::API::Account do
|
4
|
+
before do
|
5
|
+
@client = Croudia::Client.new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '#verify_credentials' do
|
9
|
+
before do
|
10
|
+
stub_get('/account/verify_credentials.json').to_return(
|
11
|
+
body: fixture(:user),
|
12
|
+
header: { content_type: 'application/json; charset=utf-8' }
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'requests the correct resource' do
|
17
|
+
@client.verify_credentials
|
18
|
+
expect(a_get('/account/verify_credentials.json')).to have_been_made
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -49,5 +49,15 @@ describe Croudia::API::OAuth do
|
|
49
49
|
client_secret: 'cs-value',
|
50
50
|
})).to have_been_made
|
51
51
|
end
|
52
|
+
|
53
|
+
it 'returns the correct token' do
|
54
|
+
access_token = @client.get_access_token(code: 'code_value')
|
55
|
+
expect(access_token['access_token']).to eq 'access_token_value'
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'can return a token via #access_token' do
|
59
|
+
access_token = @client.get_access_token(code: 'code_value')
|
60
|
+
expect(access_token.access_token).to eq 'access_token_value'
|
61
|
+
end
|
52
62
|
end
|
53
63
|
end
|
@@ -70,4 +70,18 @@ describe Croudia::API::Statuses do
|
|
70
70
|
expect(a_get('/statuses/show/1234.json')).to have_been_made
|
71
71
|
end
|
72
72
|
end
|
73
|
+
|
74
|
+
describe '#spread' do
|
75
|
+
before do
|
76
|
+
stub_post('/statuses/spread/1234.json').to_return(
|
77
|
+
body: fixture(:status),
|
78
|
+
header: { content_type: 'application/json: charset=utf-8' }
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'requests the correct resource' do
|
83
|
+
@client.spread(1234)
|
84
|
+
expect(a_post('/statuses/spread/1234.json')).to have_been_made
|
85
|
+
end
|
86
|
+
end
|
73
87
|
end
|
data/spec/croudia/base_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'helper'
|
|
2
2
|
|
3
3
|
describe Croudia::Base do
|
4
4
|
before do
|
5
|
-
@base = Croudia::Base.new(id
|
5
|
+
@base = Croudia::Base.new('id' => 1)
|
6
6
|
end
|
7
7
|
|
8
8
|
describe '#[]' do
|
@@ -21,7 +21,7 @@ describe Croudia::Base do
|
|
21
21
|
|
22
22
|
describe '#attrs' do
|
23
23
|
it 'returns a hash of attributes' do
|
24
|
-
expect(@base.attrs).to eq({id
|
24
|
+
expect(@base.attrs).to eq({'id' => 1})
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -2,27 +2,27 @@ require 'helper'
|
|
2
2
|
|
3
3
|
describe Croudia::Identity do
|
4
4
|
describe '#initialize' do
|
5
|
-
it 'raises ArguentError if
|
5
|
+
it 'raises ArguentError if "id" attr is missing' do
|
6
6
|
expect { Croudia::Identity.new }.to raise_error ArgumentError
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
10
|
describe '#==' do
|
11
11
|
it 'returns true when objects IDs are the same' do
|
12
|
-
one = Croudia::Identity.new(id
|
13
|
-
two = Croudia::Identity.new(id
|
12
|
+
one = Croudia::Identity.new('id' => 1, 'text' => 'hoge')
|
13
|
+
two = Croudia::Identity.new('id' => 1, 'text' => 'fuga')
|
14
14
|
expect(one == two).to be_true
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'returns false when objects IDs are different' do
|
18
|
-
one = Croudia::Identity.new(id
|
19
|
-
two = Croudia::Identity.new(id
|
18
|
+
one = Croudia::Identity.new('id' => 1)
|
19
|
+
two = Croudia::Identity.new('id' => 2)
|
20
20
|
expect(one == two).to be_false
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'returns false when classes are different' do
|
24
|
-
one = Croudia::Identity.new(id
|
25
|
-
two = Croudia::Base.new(id
|
24
|
+
one = Croudia::Identity.new('id' => 1)
|
25
|
+
two = Croudia::Base.new('id' => 1)
|
26
26
|
expect(one == two).to be_false
|
27
27
|
end
|
28
28
|
end
|
data/spec/croudia/status_spec.rb
CHANGED
@@ -3,27 +3,27 @@ require 'helper'
|
|
3
3
|
describe Croudia::Status do
|
4
4
|
describe '#==' do
|
5
5
|
it 'returns true when objects IDs are the same' do
|
6
|
-
status = Croudia::Status.new(id
|
7
|
-
other = Croudia::Status.new(id
|
6
|
+
status = Croudia::Status.new('id' => 1, 'text' => 'hoge')
|
7
|
+
other = Croudia::Status.new('id' => 1, 'text' => 'fuga')
|
8
8
|
expect(status == other).to be_true
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'returns false when objects IDs are different' do
|
12
|
-
status = Croudia::Status.new(id
|
13
|
-
other = Croudia::Status.new(id
|
12
|
+
status = Croudia::Status.new('id' => 1)
|
13
|
+
other = Croudia::Status.new('id' => 2)
|
14
14
|
expect(status == other).to be_false
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'returns false when classes are different' do
|
18
|
-
status = Croudia::Status.new(id
|
19
|
-
other = Croudia::Identity.new(id
|
18
|
+
status = Croudia::Status.new('id' => 1)
|
19
|
+
other = Croudia::Identity.new('id' => 1)
|
20
20
|
expect(status == other).to be_false
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
describe '#created_at' do
|
25
25
|
it 'returns a Time' do
|
26
|
-
status = Croudia::Status.new(id
|
26
|
+
status = Croudia::Status.new('id' => 3, 'created_at' => 'Mon, 08 Jul 2013 01:23:45 +0900')
|
27
27
|
expect(status.created_at).to be_a Time
|
28
28
|
end
|
29
29
|
end
|
data/spec/croudia/user_spec.rb
CHANGED
@@ -3,27 +3,27 @@ require 'helper'
|
|
3
3
|
describe Croudia::User do
|
4
4
|
describe '#==' do
|
5
5
|
it 'returns true when objects IDs are the same' do
|
6
|
-
user = Croudia::User.new(id
|
7
|
-
other = Croudia::User.new(id
|
6
|
+
user = Croudia::User.new('id' => 1, 'name' => 'hoge')
|
7
|
+
other = Croudia::User.new('id' => 1, 'name' => 'fuga')
|
8
8
|
expect(user == other).to be_true
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'returns false when objects IDs are different' do
|
12
|
-
user = Croudia::User.new(id
|
13
|
-
other = Croudia::User.new(id
|
12
|
+
user = Croudia::User.new('id' => 1)
|
13
|
+
other = Croudia::User.new('id' => 2)
|
14
14
|
expect(user == other).to be_false
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'returns false when classes are different' do
|
18
|
-
user = Croudia::User.new(id
|
19
|
-
other = Croudia::Identity.new(id
|
18
|
+
user = Croudia::User.new('id' => 1)
|
19
|
+
other = Croudia::Identity.new('id' => 1)
|
20
20
|
expect(user == other).to be_false
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
describe '#created_at' do
|
25
25
|
it 'returns a Time' do
|
26
|
-
user = Croudia::User.new(id
|
26
|
+
user = Croudia::User.new('id' => 3, 'created_at' => 'Mon, 08 2013 01:23:45 +0900')
|
27
27
|
expect(user.created_at).to be_a Time
|
28
28
|
end
|
29
29
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"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/"}
|
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.
|
4
|
+
version: 1.0.1
|
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-
|
11
|
+
date: 2013-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.9.0
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: hashie
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ~>
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 2.0.5
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ~>
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 2.0.5
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: rake
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +108,8 @@ files:
|
|
122
108
|
- Rakefile
|
123
109
|
- croudia.gemspec
|
124
110
|
- lib/croudia.rb
|
111
|
+
- lib/croudia/access_token.rb
|
112
|
+
- lib/croudia/api/account.rb
|
125
113
|
- lib/croudia/api/favorites.rb
|
126
114
|
- lib/croudia/api/oauth.rb
|
127
115
|
- lib/croudia/api/statuses.rb
|
@@ -136,6 +124,7 @@ files:
|
|
136
124
|
- lib/croudia/status.rb
|
137
125
|
- lib/croudia/user.rb
|
138
126
|
- lib/croudia/version.rb
|
127
|
+
- spec/croudia/api/account_spec.rb
|
139
128
|
- spec/croudia/api/favorites_spec.rb
|
140
129
|
- spec/croudia/api/oauth_spec.rb
|
141
130
|
- spec/croudia/api/statuses_spec.rb
|
@@ -149,9 +138,11 @@ files:
|
|
149
138
|
- spec/fixtures/access_token.json
|
150
139
|
- spec/fixtures/status.json
|
151
140
|
- spec/fixtures/timeline.json
|
141
|
+
- spec/fixtures/user.json
|
152
142
|
- spec/helper.rb
|
153
143
|
homepage: https://github.com/wktk/croudia-gem
|
154
|
-
licenses:
|
144
|
+
licenses:
|
145
|
+
- MIT
|
155
146
|
metadata: {}
|
156
147
|
post_install_message:
|
157
148
|
rdoc_options: []
|
@@ -174,6 +165,7 @@ signing_key:
|
|
174
165
|
specification_version: 4
|
175
166
|
summary: Croudia API
|
176
167
|
test_files:
|
168
|
+
- spec/croudia/api/account_spec.rb
|
177
169
|
- spec/croudia/api/favorites_spec.rb
|
178
170
|
- spec/croudia/api/oauth_spec.rb
|
179
171
|
- spec/croudia/api/statuses_spec.rb
|
@@ -187,4 +179,5 @@ test_files:
|
|
187
179
|
- spec/fixtures/access_token.json
|
188
180
|
- spec/fixtures/status.json
|
189
181
|
- spec/fixtures/timeline.json
|
182
|
+
- spec/fixtures/user.json
|
190
183
|
- spec/helper.rb
|