croudia 1.0.3 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/croudia/access_token.rb +9 -1
- data/lib/croudia/api/favorites.rb +2 -16
- data/lib/croudia/api/friendships.rb +2 -26
- data/lib/croudia/api/secret_mails.rb +58 -0
- data/lib/croudia/api/statuses.rb +7 -26
- data/lib/croudia/api/timelines.rb +5 -20
- data/lib/croudia/api/users.rb +1 -13
- data/lib/croudia/api/utils.rb +51 -0
- data/lib/croudia/base.rb +3 -10
- data/lib/croudia/client.rb +4 -0
- data/lib/croudia/secret_mail.rb +29 -0
- data/lib/croudia/status.rb +19 -8
- data/lib/croudia/user.rb +16 -3
- data/lib/croudia/version.rb +1 -1
- data/spec/croudia/api/account_spec.rb +4 -0
- data/spec/croudia/api/favorites_spec.rb +8 -0
- data/spec/croudia/api/oauth_spec.rb +4 -0
- data/spec/croudia/api/secret_mails_spec.rb +154 -0
- data/spec/croudia/api/statuses_spec.rb +18 -0
- data/spec/croudia/api/timelines_spec.rb +31 -0
- data/spec/croudia/secret_mail_spec.rb +30 -0
- data/spec/fixtures/secret_mail.json +20 -0
- data/spec/fixtures/secret_mails.json +20 -0
- metadata +13 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c74b6ada9b04df96b347e458384ad64a14744cb
|
4
|
+
data.tar.gz: 257ca2a1b2fe3e46a51b163d6f65fad0d2692e45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3612bdb2751c1f0ded07f687ecd695d36ca03275b9927d6f5aa3f614194b1a98b8d6e6f4eed13ec1ce7f9f25e5cf6514129061e8fa19ec6e9bf03b771950de6
|
7
|
+
data.tar.gz: 3c9f5ed43a01ad3e27641fc8e13afdca87194595598cc1d50b6d45609d961ae6838f72e7b9bc12e873255878d6482614babc25b036134de512ce80b9238a3b97
|
data/README.md
CHANGED
@@ -4,6 +4,9 @@
|
|
4
4
|
|
5
5
|
A Ruby Wapper for the [Croudia](https://croudia.com) API
|
6
6
|
|
7
|
+
This software is not affiliated with [Croudia Inc](http://croudia.co.jp/).
|
8
|
+
Croudia is a registered trademark of Croudia Inc. in Japan.
|
9
|
+
|
7
10
|
## Installation
|
8
11
|
|
9
12
|
Add this line to your application's Gemfile:
|
data/lib/croudia/access_token.rb
CHANGED
@@ -2,7 +2,15 @@ require 'croudia/base'
|
|
2
2
|
|
3
3
|
module Croudia
|
4
4
|
class AccessToken < Croudia::Base
|
5
|
-
|
5
|
+
KEYS = [
|
6
|
+
:access_token,
|
7
|
+
:expires_in,
|
8
|
+
:refresh_token,
|
9
|
+
:token_type,
|
10
|
+
]
|
11
|
+
|
12
|
+
attr_reader(*KEYS)
|
13
|
+
|
6
14
|
alias :token :access_token
|
7
15
|
|
8
16
|
def to_s
|
@@ -9,14 +9,7 @@ module Croudia
|
|
9
9
|
# @param params [Hash]
|
10
10
|
# @return [Croudia::Status] Favorited status
|
11
11
|
def favorite(status_id, params={})
|
12
|
-
|
13
|
-
when String, Integer
|
14
|
-
when Croudia::Status
|
15
|
-
status_id = status_id.id_str
|
16
|
-
else
|
17
|
-
raise ArgumentError, 'status_id is invalid'
|
18
|
-
end
|
19
|
-
|
12
|
+
status_id = get_id(status_id)
|
20
13
|
resp = post("/favorites/create/#{status_id}.json", params)
|
21
14
|
Croudia::Status.new(resp)
|
22
15
|
end
|
@@ -27,14 +20,7 @@ module Croudia
|
|
27
20
|
# @param params [Hash]
|
28
21
|
# @return [Croudia::Status] Unfavorited status
|
29
22
|
def unfavorite(status_id, params={})
|
30
|
-
|
31
|
-
when String, Integer
|
32
|
-
when Croudia::Status
|
33
|
-
status_id = status_id.id_str
|
34
|
-
else
|
35
|
-
raise ArgumentError, 'status_id is invalid'
|
36
|
-
end
|
37
|
-
|
23
|
+
status_id = get_id(status_id)
|
38
24
|
resp = delete("/favorites/destroy/#{status_id}.json", params)
|
39
25
|
Croudia::Status.new(resp)
|
40
26
|
end
|
@@ -9,19 +9,7 @@ module Croudia
|
|
9
9
|
# @param params [Hash] Optional params
|
10
10
|
# @return [Croudia::User] Followed user
|
11
11
|
def follow(user, params={})
|
12
|
-
|
13
|
-
when Hash
|
14
|
-
params.merge!(user)
|
15
|
-
when String
|
16
|
-
params[:screen_name] = user
|
17
|
-
when Integer
|
18
|
-
params[:user_id] = user
|
19
|
-
when Croudia::User
|
20
|
-
params[:user_id] = user.id_str
|
21
|
-
else
|
22
|
-
raise ArgumentError, 'user must be a String, Integer or User'
|
23
|
-
end
|
24
|
-
|
12
|
+
merge_user!(params, user)
|
25
13
|
resp = post('/friendships/create.json', params)
|
26
14
|
Croudia::User.new(resp)
|
27
15
|
end
|
@@ -32,19 +20,7 @@ module Croudia
|
|
32
20
|
# @param params
|
33
21
|
# @return [Croudia::User] Unfollowed user
|
34
22
|
def unfollow(user, params={})
|
35
|
-
|
36
|
-
when Hash
|
37
|
-
params.merge!(user)
|
38
|
-
when String
|
39
|
-
params[:screen_name] = user
|
40
|
-
when Integer
|
41
|
-
params[:user_id] = user
|
42
|
-
when Croudia::user
|
43
|
-
params[:user_id] = user.id_str
|
44
|
-
else
|
45
|
-
raise ArgumentError, 'user must be a String, Integer or User'
|
46
|
-
end
|
47
|
-
|
23
|
+
merge_user!(params, user)
|
48
24
|
resp = post('/friendships/destroy.json', params)
|
49
25
|
Croudia::User.new(resp)
|
50
26
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'croudia/secret_mail'
|
2
|
+
|
3
|
+
module Croudia
|
4
|
+
module API
|
5
|
+
module SecretMails
|
6
|
+
# Get incoming secret mails
|
7
|
+
#
|
8
|
+
# @param params [Hash]
|
9
|
+
# @return [Array<Croudia::SecretMails>]
|
10
|
+
def secret_mails(params={})
|
11
|
+
resp = get('/secret_mails.json', params)
|
12
|
+
objects(Croudia::SecretMail, resp)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Get outgoing secret mails
|
16
|
+
#
|
17
|
+
# @param params [Hash]
|
18
|
+
# @return [Array<Croudia::SecretMail>]
|
19
|
+
def secret_mails_sent(params={})
|
20
|
+
resp = get('/secret_mails/sent.json', params)
|
21
|
+
objects(Croudia::SecretMail, resp)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Send a new secret mail
|
25
|
+
#
|
26
|
+
# @param text [String] Message body
|
27
|
+
# @param to_user [String, Integer, Croudia::User] Recipient user
|
28
|
+
# @param params [Hash]
|
29
|
+
def send_secret_mail(text, to_user={}, params={})
|
30
|
+
merge_text!(params, text, :text)
|
31
|
+
merge_user!(params, to_user)
|
32
|
+
|
33
|
+
resp = post('/secret_mails/new.json', params)
|
34
|
+
Croudia::SecretMail.new(resp)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Destroy a secret mail
|
38
|
+
#
|
39
|
+
# @param id [Integer, String, Croudia::SecretMail]
|
40
|
+
# @param params [Hash]
|
41
|
+
# @return [Croudia::SecretMail]
|
42
|
+
def destroy_secret_mail(id, params={})
|
43
|
+
resp = post("/secret_mails/destroy/#{get_id(id)}.json", params)
|
44
|
+
Croudia::SecretMail.new(resp)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Get a secret mail
|
48
|
+
#
|
49
|
+
# @param id [Integer, String, Croudia::SecretMail]
|
50
|
+
# @param params [Hash]
|
51
|
+
# @return [Croudia::SecretMail]
|
52
|
+
def show_secret_mail(id, params={})
|
53
|
+
resp = get("/secret_mails/show/#{get_id(id)}.json", params)
|
54
|
+
Croudia::SecretMail.new(resp)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/croudia/api/statuses.rb
CHANGED
@@ -8,13 +8,8 @@ module Croudia
|
|
8
8
|
# @param status [String] Status text
|
9
9
|
# @param params [Hash] Additional params
|
10
10
|
# @return status [Croudia::Status] Posted status
|
11
|
-
def update(
|
12
|
-
|
13
|
-
when String
|
14
|
-
params[:status] ||= status
|
15
|
-
when Hash
|
16
|
-
params = status.merge(params)
|
17
|
-
end
|
11
|
+
def update(text, params={})
|
12
|
+
merge_text!(params, text)
|
18
13
|
|
19
14
|
resp = post('/statuses/update.json', params)
|
20
15
|
Croudia::Status.new(resp)
|
@@ -26,13 +21,9 @@ module Croudia
|
|
26
21
|
# @param params [Hash]
|
27
22
|
# @return [Croudia::Status] Deleted status
|
28
23
|
def destroy_status(status_id, params={})
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
status_id = status_id.id_str
|
33
|
-
end
|
34
|
-
|
35
|
-
post("/statuses/destroy/#{status_id}.json", params)
|
24
|
+
status_id = get_id(status_id)
|
25
|
+
resp = post("/statuses/destroy/#{status_id}.json", params)
|
26
|
+
Croudia::Status.new(resp)
|
36
27
|
end
|
37
28
|
|
38
29
|
# Retrieve a status
|
@@ -41,12 +32,7 @@ module Croudia
|
|
41
32
|
# @param params [Hash]
|
42
33
|
# @return [Croudia::Status]
|
43
34
|
def status(status_id, params={})
|
44
|
-
|
45
|
-
when String, Integer
|
46
|
-
when Croudia::Status
|
47
|
-
status_id = status_id.id_str
|
48
|
-
end
|
49
|
-
|
35
|
+
status_id = get_id(status_id)
|
50
36
|
resp = get("/statuses/show/#{status_id}.json", params)
|
51
37
|
Croudia::Status.new(resp)
|
52
38
|
end
|
@@ -57,12 +43,7 @@ module Croudia
|
|
57
43
|
# @param params [Hash]
|
58
44
|
# @return [Croudia::Status] My status including spreaded status
|
59
45
|
def spread(status_id, params={})
|
60
|
-
|
61
|
-
when String, Integer
|
62
|
-
when Croudia::Status
|
63
|
-
status_id = status_id.id_str
|
64
|
-
end
|
65
|
-
|
46
|
+
status_id = get_id(status_id)
|
66
47
|
resp = post("/statuses/spread/#{status_id}.json", params)
|
67
48
|
Croudia::Status.new(resp)
|
68
49
|
end
|
@@ -9,7 +9,7 @@ module Croudia
|
|
9
9
|
# @return [Array<Croudia::Status>]
|
10
10
|
def public_timeline(params={})
|
11
11
|
resp = get('/statuses/public_timeline.json', params)
|
12
|
-
|
12
|
+
objects(Croudia::Status, resp)
|
13
13
|
end
|
14
14
|
|
15
15
|
# Home Timeline
|
@@ -18,7 +18,7 @@ module Croudia
|
|
18
18
|
# @return [Array<Croudia::Status>]
|
19
19
|
def home_timeline(params={})
|
20
20
|
resp = get('/statuses/home_timeline.json', params)
|
21
|
-
|
21
|
+
objects(Croudia::Status, resp)
|
22
22
|
end
|
23
23
|
|
24
24
|
# User Timeline
|
@@ -27,31 +27,16 @@ module Croudia
|
|
27
27
|
# @param params [Hash]
|
28
28
|
# @return [Array<Croudia::Status>
|
29
29
|
def user_timeline(user, params={})
|
30
|
-
|
31
|
-
when String
|
32
|
-
params[:screen_name] ||= user
|
33
|
-
when Integer
|
34
|
-
params[:user_id] ||= user
|
35
|
-
when Croudia::User
|
36
|
-
params[:user_id] ||= user.id_str
|
37
|
-
when Hash
|
38
|
-
params = user.merge(params)
|
39
|
-
end
|
40
|
-
|
30
|
+
merge_user!(params, user)
|
41
31
|
resp = get('/statuses/user_timeline.json', params)
|
42
|
-
|
32
|
+
objects(Croudia::Status, resp)
|
43
33
|
end
|
44
34
|
|
45
35
|
def mentions(params={})
|
46
36
|
resp = get('/statuses/mentions.json', params)
|
47
|
-
|
37
|
+
objects(Croudia::Status, resp)
|
48
38
|
end
|
49
39
|
alias mentions_timeline mentions
|
50
|
-
|
51
|
-
private
|
52
|
-
def objectify_statuses(statuses)
|
53
|
-
statuses.map { |status| Croudia::Status.new(status) }
|
54
|
-
end
|
55
40
|
end
|
56
41
|
end
|
57
42
|
end
|
data/lib/croudia/api/users.rb
CHANGED
@@ -9,19 +9,7 @@ module Croudia
|
|
9
9
|
# @param params [Hash] Optional params
|
10
10
|
# @return [Croudia::User]
|
11
11
|
def user(user, params={})
|
12
|
-
|
13
|
-
when Hash
|
14
|
-
params.merge!(user)
|
15
|
-
when String
|
16
|
-
params[:screen_name] = user
|
17
|
-
when Integer
|
18
|
-
params[:user_id] = user
|
19
|
-
when Croudia::User
|
20
|
-
params[:user_id] = user.id_str
|
21
|
-
else
|
22
|
-
raise ArgumentError, 'user must be a String, Integer or User'
|
23
|
-
end
|
24
|
-
|
12
|
+
merge_user!(params, user)
|
25
13
|
resp = get('/users/show.json', params)
|
26
14
|
Croudia::User.new(resp)
|
27
15
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Croudia
|
2
|
+
module API
|
3
|
+
module Utils
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def get_id(id)
|
8
|
+
case id
|
9
|
+
when String, Integer
|
10
|
+
id
|
11
|
+
when Croudia::Identity
|
12
|
+
id.id_str
|
13
|
+
else
|
14
|
+
raise ArgumentError, 'id is invalid'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def merge_user!(params, user)
|
19
|
+
case user
|
20
|
+
when Hash
|
21
|
+
params.merge!(user)
|
22
|
+
when String
|
23
|
+
params[:screen_name] = user
|
24
|
+
when Integer
|
25
|
+
params[:user_id] = user
|
26
|
+
when Croudia::User
|
27
|
+
params[:user_id] = user.id_str
|
28
|
+
else
|
29
|
+
raise ArgumentError, 'user must be a String, Integer or User'
|
30
|
+
end
|
31
|
+
|
32
|
+
params
|
33
|
+
end
|
34
|
+
|
35
|
+
def merge_text!(params, text, key=:status)
|
36
|
+
case text
|
37
|
+
when Hash
|
38
|
+
params.merge!(text)
|
39
|
+
else
|
40
|
+
params[key] ||= text.to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
params
|
44
|
+
end
|
45
|
+
|
46
|
+
def objects(klass, array)
|
47
|
+
array.map { |hash| klass.new(hash) }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/croudia/base.rb
CHANGED
@@ -2,18 +2,11 @@ module Croudia
|
|
2
2
|
class Base
|
3
3
|
class << self
|
4
4
|
def attr_reader(*attrs)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
@attrs[attr.to_s] || @attrs[attr.to_sym]
|
9
|
-
end
|
10
|
-
define_method("#{attr}?") do
|
11
|
-
!!(@attrs[attr.to_s] || @attrs[attr.to_sym])
|
12
|
-
end
|
5
|
+
attrs.each do |attr|
|
6
|
+
define_method(attr) do
|
7
|
+
@attrs[attr.to_s] || @attrs[attr.to_sym]
|
13
8
|
end
|
14
9
|
end
|
15
|
-
const_set(:Attributes, mod)
|
16
|
-
include mod
|
17
10
|
end
|
18
11
|
end
|
19
12
|
|
data/lib/croudia/client.rb
CHANGED
@@ -2,9 +2,11 @@ require 'croudia/api/account'
|
|
2
2
|
require 'croudia/api/favorites'
|
3
3
|
require 'croudia/api/friendships'
|
4
4
|
require 'croudia/api/oauth'
|
5
|
+
require 'croudia/api/secret_mails'
|
5
6
|
require 'croudia/api/statuses'
|
6
7
|
require 'croudia/api/timelines'
|
7
8
|
require 'croudia/api/users'
|
9
|
+
require 'croudia/api/utils'
|
8
10
|
require 'croudia/configurable'
|
9
11
|
require 'croudia/ext/openssl'
|
10
12
|
require 'croudia/version'
|
@@ -16,9 +18,11 @@ module Croudia
|
|
16
18
|
include Croudia::API::Favorites
|
17
19
|
include Croudia::API::Friendships
|
18
20
|
include Croudia::API::OAuth
|
21
|
+
include Croudia::API::SecretMails
|
19
22
|
include Croudia::API::Statuses
|
20
23
|
include Croudia::API::Timelines
|
21
24
|
include Croudia::API::Users
|
25
|
+
include Croudia::API::Utils
|
22
26
|
include Croudia::Configurable
|
23
27
|
|
24
28
|
# Initialize a new Client object
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'croudia/identity'
|
2
|
+
require 'croudia/creatable'
|
3
|
+
|
4
|
+
module Croudia
|
5
|
+
class SecretMail < Croudia::Identity
|
6
|
+
include Croudia::Creatable
|
7
|
+
|
8
|
+
KEYS = [
|
9
|
+
:id_str,
|
10
|
+
:recipient,
|
11
|
+
:recipient_id,
|
12
|
+
:recipient_screen_name,
|
13
|
+
:sender,
|
14
|
+
:sender_id,
|
15
|
+
:sender_screen_name,
|
16
|
+
:text,
|
17
|
+
]
|
18
|
+
|
19
|
+
attr_reader(*KEYS)
|
20
|
+
|
21
|
+
def initialize(attrs)
|
22
|
+
recipient = attrs.delete('recipient')
|
23
|
+
sender = attrs.delete('sender')
|
24
|
+
super(attrs)
|
25
|
+
@attrs['recipient'] = Croudia::User.new(recipient) if recipient
|
26
|
+
@attrs['sender'] = Croudia::User.new(sender) if sender
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/croudia/status.rb
CHANGED
@@ -6,21 +6,32 @@ module Croudia
|
|
6
6
|
class Status < Croudia::Identity
|
7
7
|
include Croudia::Creatable
|
8
8
|
|
9
|
-
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
9
|
+
KEYS = [
|
10
|
+
:id_str,
|
11
|
+
:favorited,
|
12
|
+
:favorited_count,
|
13
|
+
:in_reply_to_screen_name,
|
14
|
+
:in_reply_to_status_id_str,
|
15
|
+
:in_reply_to_status_id,
|
16
|
+
:in_reply_to_user_id_str,
|
17
|
+
:in_reply_to_user_id,
|
18
|
+
:spread,
|
19
|
+
:spread_count,
|
20
|
+
:spread_status,
|
21
|
+
:reply_status,
|
22
|
+
:source,
|
23
|
+
:text,
|
24
|
+
:user,
|
25
|
+
]
|
26
|
+
|
27
|
+
attr_reader(*KEYS)
|
15
28
|
|
16
29
|
def initialize(attrs={})
|
17
30
|
user = attrs.delete('user')
|
18
|
-
pss = attrs.delete('play_spread_status')
|
19
31
|
reply_status = attrs.delete('reply_status')
|
20
32
|
spread_status = attrs.delete('spread_status')
|
21
33
|
super(attrs)
|
22
34
|
@attrs['user'] = Croudia::User.new(user) if user
|
23
|
-
@attrs['play_spread_status'] = Croudia::Status.new(pss) if pss
|
24
35
|
@attrs['reply_status'] = Croudia::Status.new(reply_status) if reply_status
|
25
36
|
@attrs['spread_status'] = Croudia::Status.new(spread_status) if spread_status
|
26
37
|
end
|
data/lib/croudia/user.rb
CHANGED
@@ -5,8 +5,21 @@ module Croudia
|
|
5
5
|
class User < Croudia::Identity
|
6
6
|
include Croudia::Creatable
|
7
7
|
|
8
|
-
|
9
|
-
:
|
10
|
-
:
|
8
|
+
KEYS = [
|
9
|
+
:id_str,
|
10
|
+
:description,
|
11
|
+
:favorites_count,
|
12
|
+
:follow_request_sent,
|
13
|
+
:followers_count,
|
14
|
+
:friends_count,
|
15
|
+
:location,
|
16
|
+
:name,
|
17
|
+
:profile_image_url_https,
|
18
|
+
:screen_name,
|
19
|
+
:statuses_count,
|
20
|
+
:url,
|
21
|
+
]
|
22
|
+
|
23
|
+
attr_reader(*KEYS)
|
11
24
|
end
|
12
25
|
end
|
data/lib/croudia/version.rb
CHANGED
@@ -17,6 +17,10 @@ describe Croudia::API::Favorites do
|
|
17
17
|
@client.favorite(1234)
|
18
18
|
expect(a_post('/favorites/create/1234.json')).to have_been_made
|
19
19
|
end
|
20
|
+
|
21
|
+
it 'returns a Status object' do
|
22
|
+
expect(@client.favorite(1234)).to be_a Croudia::Status
|
23
|
+
end
|
20
24
|
end
|
21
25
|
|
22
26
|
describe '#unfavorite' do
|
@@ -31,5 +35,9 @@ describe Croudia::API::Favorites do
|
|
31
35
|
@client.unfavorite(1234)
|
32
36
|
expect(a_delete('/favorites/destroy/1234.json')).to have_been_made
|
33
37
|
end
|
38
|
+
|
39
|
+
it 'returns a Status object' do
|
40
|
+
expect(@client.unfavorite(1234)).to be_a Croudia::Status
|
41
|
+
end
|
34
42
|
end
|
35
43
|
end
|
@@ -55,6 +55,10 @@ describe Croudia::API::OAuth do
|
|
55
55
|
expect(access_token['access_token']).to eq 'access_token_value'
|
56
56
|
end
|
57
57
|
|
58
|
+
it 'returns AccessToken object' do
|
59
|
+
expect(@client.get_access_token('code_value')).to be_a Croudia::AccessToken
|
60
|
+
end
|
61
|
+
|
58
62
|
it 'can return a token via #access_token' do
|
59
63
|
access_token = @client.get_access_token(code: 'code_value')
|
60
64
|
expect(access_token.access_token).to eq 'access_token_value'
|
@@ -0,0 +1,154 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Croudia::API::SecretMails do
|
4
|
+
before do
|
5
|
+
@client = Croudia::Client.new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '#secret_mails' do
|
9
|
+
before do
|
10
|
+
stub_get('/secret_mails.json').to_return(
|
11
|
+
body: fixture(:secret_mails),
|
12
|
+
header: { content_type: 'application/json; charset=utf-8' }
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'requests the correct resource' do
|
17
|
+
@client.secret_mails
|
18
|
+
expect(a_get('/secret_mails.json')).to have_been_made
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'returns Array of Croudia::SecretMail' do
|
22
|
+
subject = @client.secret_mails
|
23
|
+
expect(subject).to be_an Array
|
24
|
+
subject.each { |s| expect(s).to be_a Croudia::SecretMail }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#secret_mails_sent' do
|
29
|
+
before do
|
30
|
+
stub_get('/secret_mails/sent.json').to_return(
|
31
|
+
body: fixture(:secret_mails),
|
32
|
+
header: { content_type: 'application/json; charset=utf-8' }
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'requests the correct resource' do
|
37
|
+
@client.secret_mails_sent
|
38
|
+
expect(a_get('/secret_mails/sent.json')).to have_been_made
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'returns Array of Croudia::SecretMail' do
|
42
|
+
subject = @client.secret_mails_sent
|
43
|
+
expect(subject).to be_an Array
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#send_secret_mail' do
|
48
|
+
before do
|
49
|
+
stub_post('/secret_mails/new.json').to_return(
|
50
|
+
body: fixture(:secret_mail),
|
51
|
+
headers: { content_type: 'application/json; charset=utf-8' }
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'when passing text as the first argument' do
|
56
|
+
context 'when passing user as String (screen_name)' do
|
57
|
+
it 'requests the correct resource' do
|
58
|
+
@client.send_secret_mail('Hello', 'wktk')
|
59
|
+
expect(a_post('/secret_mails/new.json').with(
|
60
|
+
body: {
|
61
|
+
text: 'Hello',
|
62
|
+
screen_name: 'wktk',
|
63
|
+
}
|
64
|
+
)).to have_been_made
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'when passing user as Integer (user_id)' do
|
69
|
+
it 'requests the correct resource' do
|
70
|
+
@client.send_secret_mail('Hello?', 1234)
|
71
|
+
expect(a_post('/secret_mails/new.json').with(
|
72
|
+
body: {
|
73
|
+
text: 'Hello?',
|
74
|
+
user_id: '1234',
|
75
|
+
}
|
76
|
+
)).to have_been_made
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'when passing user as Croudia::User' do
|
81
|
+
it 'requests the correct resource' do
|
82
|
+
user = Croudia::User.new('id' => 1234)
|
83
|
+
@client.send_secret_mail('Hello!', user)
|
84
|
+
expect(a_post('/secret_mails/new.json').with(
|
85
|
+
body: {
|
86
|
+
text: 'Hello!',
|
87
|
+
user_id: '1234',
|
88
|
+
}
|
89
|
+
)).to have_been_made
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'when passing all params as Hash' do
|
95
|
+
it 'requests the correct resource' do
|
96
|
+
@client.send_secret_mail(text: 'Hi', screen_name: 'wktk')
|
97
|
+
expect(a_post('/secret_mails/new.json').with(
|
98
|
+
body: {
|
99
|
+
text: 'Hi',
|
100
|
+
screen_name: 'wktk',
|
101
|
+
}
|
102
|
+
)).to have_been_made
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'returns Croudia::SecretMail' do
|
107
|
+
subject = @client.send_secret_mail('hi', 1234)
|
108
|
+
expect(subject).to be_a Croudia::SecretMail
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '#destroy_secret_mail' do
|
113
|
+
before do
|
114
|
+
stub_post('/secret_mails/destroy/1234.json').to_return(
|
115
|
+
body: fixture(:secret_mail),
|
116
|
+
headers: { content_type: 'application/json; charset-utf-8' }
|
117
|
+
)
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'requests the correct resource' do
|
121
|
+
@client.destroy_secret_mail(1234)
|
122
|
+
expect(a_post('/secret_mails/destroy/1234.json')).to have_been_made
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'can destroy Croudia::SecretMail' do
|
126
|
+
@client.destroy_secret_mail(Croudia::SecretMail.new('id' => 1234))
|
127
|
+
expect(a_post('/secret_mails/destroy/1234.json')).to have_been_made
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'returns Croudia::SecretMail' do
|
131
|
+
subject = @client.destroy_secret_mail(1234)
|
132
|
+
expect(subject).to be_a Croudia::SecretMail
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe '#show_secret_mail' do
|
137
|
+
before do
|
138
|
+
stub_get('/secret_mails/show/1234.json').to_return(
|
139
|
+
body: fixture(:secret_mail),
|
140
|
+
headers: { content_type: 'appplication/json; charset=utf-8' }
|
141
|
+
)
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'requests the correct resource' do
|
145
|
+
@client.show_secret_mail(1234)
|
146
|
+
expect(a_get('/secret_mails/show/1234.json')).to have_been_made
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'returns Croudia::SecretMail' do
|
150
|
+
subject = @client.show_secret_mail(1234)
|
151
|
+
expect(subject).to be_a Croudia::SecretMail
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
@@ -41,6 +41,12 @@ describe Croudia::API::Statuses do
|
|
41
41
|
)).to have_been_made
|
42
42
|
end
|
43
43
|
end
|
44
|
+
|
45
|
+
it 'returns a Status object' do
|
46
|
+
expect(
|
47
|
+
@client.update('Hello', in_reply_to_status_id: 1234)
|
48
|
+
).to be_a Croudia::Status
|
49
|
+
end
|
44
50
|
end
|
45
51
|
|
46
52
|
describe '#destroy_status' do
|
@@ -55,6 +61,10 @@ describe Croudia::API::Statuses do
|
|
55
61
|
@client.destroy_status(1234)
|
56
62
|
expect(a_post('/statuses/destroy/1234.json')).to have_been_made
|
57
63
|
end
|
64
|
+
|
65
|
+
it 'returns a Status object' do
|
66
|
+
expect(@client.destroy_status(1234)).to be_a Croudia::Status
|
67
|
+
end
|
58
68
|
end
|
59
69
|
|
60
70
|
describe '#status' do
|
@@ -69,6 +79,10 @@ describe Croudia::API::Statuses do
|
|
69
79
|
@client.status(1234)
|
70
80
|
expect(a_get('/statuses/show/1234.json')).to have_been_made
|
71
81
|
end
|
82
|
+
|
83
|
+
it 'returns a Status object' do
|
84
|
+
expect(@client.status(1234)).to be_a Croudia::Status
|
85
|
+
end
|
72
86
|
end
|
73
87
|
|
74
88
|
describe '#spread' do
|
@@ -83,5 +97,9 @@ describe Croudia::API::Statuses do
|
|
83
97
|
@client.spread(1234)
|
84
98
|
expect(a_post('/statuses/spread/1234.json')).to have_been_made
|
85
99
|
end
|
100
|
+
|
101
|
+
it 'returns a Status object' do
|
102
|
+
expect(@client.spread(1234)).to be_a Croudia::Status
|
103
|
+
end
|
86
104
|
end
|
87
105
|
end
|
@@ -17,6 +17,12 @@ describe Croudia::API::Timelines do
|
|
17
17
|
@client.public_timeline
|
18
18
|
expect(a_get('/statuses/public_timeline.json')).to have_been_made
|
19
19
|
end
|
20
|
+
|
21
|
+
it 'returns array of Status object' do
|
22
|
+
tl = @client.public_timeline
|
23
|
+
expect(tl).to be_a Array
|
24
|
+
tl.each { |status| expect(status).to be_a Croudia::Status }
|
25
|
+
end
|
20
26
|
end
|
21
27
|
|
22
28
|
describe '#home_timeline' do
|
@@ -31,6 +37,12 @@ describe Croudia::API::Timelines do
|
|
31
37
|
@client.home_timeline
|
32
38
|
expect(a_get('/statuses/home_timeline.json')).to have_been_made
|
33
39
|
end
|
40
|
+
|
41
|
+
it 'returns array of Status object' do
|
42
|
+
tl = @client.home_timeline
|
43
|
+
expect(tl).to be_a Array
|
44
|
+
tl.each { |status| expect(status).to be_a Croudia::Status }
|
45
|
+
end
|
34
46
|
end
|
35
47
|
|
36
48
|
describe '#user_timeline' do
|
@@ -75,6 +87,19 @@ describe Croudia::API::Timelines do
|
|
75
87
|
)).to have_been_made
|
76
88
|
end
|
77
89
|
end
|
90
|
+
|
91
|
+
it 'returns array of Status object' do
|
92
|
+
stub_get('/statuses/user_timeline.json').with(
|
93
|
+
query: { screen_name: 'wktk' }
|
94
|
+
).to_return(
|
95
|
+
body: fixture(:timeline),
|
96
|
+
headers: { content_type: 'application/json; charset=utf-8' }
|
97
|
+
)
|
98
|
+
|
99
|
+
tl = @client.user_timeline('wktk')
|
100
|
+
expect(tl).to be_a Array
|
101
|
+
tl.each { |status| expect(status).to be_a Croudia::Status }
|
102
|
+
end
|
78
103
|
end
|
79
104
|
|
80
105
|
describe '#mentions' do
|
@@ -89,5 +114,11 @@ describe Croudia::API::Timelines do
|
|
89
114
|
@client.mentions
|
90
115
|
expect(a_get('/statuses/mentions.json')).to have_been_made
|
91
116
|
end
|
117
|
+
|
118
|
+
it 'returns array of Status object' do
|
119
|
+
tl = @client.mentions
|
120
|
+
expect(tl).to be_a Array
|
121
|
+
tl.each { |status| expect(status).to be_a Croudia::Status }
|
122
|
+
end
|
92
123
|
end
|
93
124
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Croudia::SecretMail do
|
4
|
+
describe '#==' do
|
5
|
+
it 'returns true when objects IDs are the same' do
|
6
|
+
user = Croudia::SecretMail.new('id' => 1, 'text' => 'hoge')
|
7
|
+
other = Croudia::SecretMail.new('id' => 1, 'text' => 'fuga')
|
8
|
+
expect(user == other).to be_true
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'returns false when objects IDs are different' do
|
12
|
+
user = Croudia::SecretMail.new('id' => 1, 'text' => 'hoge')
|
13
|
+
other = Croudia::SecretMail.new('id' => 2, 'text' => 'hoge')
|
14
|
+
expect(user == other).to be_false
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'returns false when classes are different' do
|
18
|
+
user = Croudia::SecretMail.new('id' => 1)
|
19
|
+
other = Croudia::Identity.new('id' => 1)
|
20
|
+
expect(user == other).to be_false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#created_at' do
|
25
|
+
it 'returns a Time' do
|
26
|
+
user = Croudia::SecretMail.new('id' => 3, 'created_at' => 'Mon, 08 2013 01:23:45 +0900')
|
27
|
+
expect(user.created_at).to be_a Time
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
{
|
2
|
+
"id": 1,
|
3
|
+
"id_str": "1",
|
4
|
+
"created_at": "Sat 20, Jul 2013 19:00:00 +0900",
|
5
|
+
"recipient": {
|
6
|
+
"id": 1234,
|
7
|
+
"id_str": "1234",
|
8
|
+
"screen_name": "wktk"
|
9
|
+
},
|
10
|
+
"recipient_id": 1234,
|
11
|
+
"recipient_screen_name": "wktk",
|
12
|
+
"sender": {
|
13
|
+
"id": 4321,
|
14
|
+
"id_str": "4321",
|
15
|
+
"screen_name": "croudia"
|
16
|
+
},
|
17
|
+
"sender_id": 4321,
|
18
|
+
"sender_screen_name": "croudia",
|
19
|
+
"text": "Hello"
|
20
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
[{
|
2
|
+
"id": 1,
|
3
|
+
"id_str": "1",
|
4
|
+
"created_at": "Sat 20, Jul 2013 19:00:00 +0900",
|
5
|
+
"recipient": {
|
6
|
+
"id": 1234,
|
7
|
+
"id_str": "1234",
|
8
|
+
"screen_name": "wktk"
|
9
|
+
},
|
10
|
+
"recipient_id": 1234,
|
11
|
+
"recipient_screen_name": "wktk",
|
12
|
+
"sender": {
|
13
|
+
"id": 4321,
|
14
|
+
"id_str": "4321",
|
15
|
+
"screen_name": "croudia"
|
16
|
+
},
|
17
|
+
"sender_id": 4321,
|
18
|
+
"sender_screen_name": "croudia",
|
19
|
+
"text": "Hello"
|
20
|
+
}]
|
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.5
|
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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -114,9 +114,11 @@ files:
|
|
114
114
|
- lib/croudia/api/favorites.rb
|
115
115
|
- lib/croudia/api/friendships.rb
|
116
116
|
- lib/croudia/api/oauth.rb
|
117
|
+
- lib/croudia/api/secret_mails.rb
|
117
118
|
- lib/croudia/api/statuses.rb
|
118
119
|
- lib/croudia/api/timelines.rb
|
119
120
|
- lib/croudia/api/users.rb
|
121
|
+
- lib/croudia/api/utils.rb
|
120
122
|
- lib/croudia/base.rb
|
121
123
|
- lib/croudia/client.rb
|
122
124
|
- lib/croudia/configurable.rb
|
@@ -124,6 +126,7 @@ files:
|
|
124
126
|
- lib/croudia/default.rb
|
125
127
|
- lib/croudia/ext/openssl.rb
|
126
128
|
- lib/croudia/identity.rb
|
129
|
+
- lib/croudia/secret_mail.rb
|
127
130
|
- lib/croudia/status.rb
|
128
131
|
- lib/croudia/user.rb
|
129
132
|
- lib/croudia/version.rb
|
@@ -131,16 +134,20 @@ files:
|
|
131
134
|
- spec/croudia/api/favorites_spec.rb
|
132
135
|
- spec/croudia/api/friendships_spec.rb
|
133
136
|
- spec/croudia/api/oauth_spec.rb
|
137
|
+
- spec/croudia/api/secret_mails_spec.rb
|
134
138
|
- spec/croudia/api/statuses_spec.rb
|
135
139
|
- spec/croudia/api/timelines_spec.rb
|
136
140
|
- spec/croudia/api/user_spec.rb
|
137
141
|
- spec/croudia/base_spec.rb
|
138
142
|
- spec/croudia/client_spec.rb
|
139
143
|
- spec/croudia/identity_spec.rb
|
144
|
+
- spec/croudia/secret_mail_spec.rb
|
140
145
|
- spec/croudia/status_spec.rb
|
141
146
|
- spec/croudia/user_spec.rb
|
142
147
|
- spec/croudia_spec.rb
|
143
148
|
- spec/fixtures/access_token.json
|
149
|
+
- spec/fixtures/secret_mail.json
|
150
|
+
- spec/fixtures/secret_mails.json
|
144
151
|
- spec/fixtures/status.json
|
145
152
|
- spec/fixtures/timeline.json
|
146
153
|
- spec/fixtures/user.json
|
@@ -174,16 +181,20 @@ test_files:
|
|
174
181
|
- spec/croudia/api/favorites_spec.rb
|
175
182
|
- spec/croudia/api/friendships_spec.rb
|
176
183
|
- spec/croudia/api/oauth_spec.rb
|
184
|
+
- spec/croudia/api/secret_mails_spec.rb
|
177
185
|
- spec/croudia/api/statuses_spec.rb
|
178
186
|
- spec/croudia/api/timelines_spec.rb
|
179
187
|
- spec/croudia/api/user_spec.rb
|
180
188
|
- spec/croudia/base_spec.rb
|
181
189
|
- spec/croudia/client_spec.rb
|
182
190
|
- spec/croudia/identity_spec.rb
|
191
|
+
- spec/croudia/secret_mail_spec.rb
|
183
192
|
- spec/croudia/status_spec.rb
|
184
193
|
- spec/croudia/user_spec.rb
|
185
194
|
- spec/croudia_spec.rb
|
186
195
|
- spec/fixtures/access_token.json
|
196
|
+
- spec/fixtures/secret_mail.json
|
197
|
+
- spec/fixtures/secret_mails.json
|
187
198
|
- spec/fixtures/status.json
|
188
199
|
- spec/fixtures/timeline.json
|
189
200
|
- spec/fixtures/user.json
|