the86-client 0.0.5 → 0.0.6
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.
- data/lib/the86-client.rb +1 -0
- data/lib/the86-client/can_be_hidden.rb +21 -0
- data/lib/the86-client/conversation.rb +2 -0
- data/lib/the86-client/post.rb +2 -16
- data/lib/the86-client/version.rb +1 -1
- data/spec/conversations_spec.rb +40 -4
- data/spec/posts_spec.rb +37 -56
- metadata +3 -2
data/lib/the86-client.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
module The86::Client
|
2
|
+
module CanBeHidden
|
3
|
+
|
4
|
+
def hide(attributes = {})
|
5
|
+
set_hidden(true, attributes)
|
6
|
+
end
|
7
|
+
|
8
|
+
def unhide(attributes = {})
|
9
|
+
set_hidden(false, attributes)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def set_hidden(hidden, attributes)
|
15
|
+
self.oauth_token = attributes[:oauth_token]
|
16
|
+
key = oauth_token ? :hidden_by_user : :hidden_by_site
|
17
|
+
patch(key => hidden)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
data/lib/the86-client/post.rb
CHANGED
@@ -12,6 +12,8 @@ module The86::Client
|
|
12
12
|
has_one :user, ->{ User }
|
13
13
|
has_one :in_reply_to, ->{ Post }
|
14
14
|
|
15
|
+
include CanBeHidden
|
16
|
+
|
15
17
|
def reply?
|
16
18
|
!!in_reply_to_id
|
17
19
|
end
|
@@ -22,21 +24,5 @@ module The86::Client
|
|
22
24
|
)
|
23
25
|
end
|
24
26
|
|
25
|
-
def hide(attributes = {})
|
26
|
-
set_hidden(true, attributes)
|
27
|
-
end
|
28
|
-
|
29
|
-
def unhide(attributes = {})
|
30
|
-
set_hidden(false, attributes)
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def set_hidden(hidden, attributes)
|
36
|
-
self.oauth_token = attributes[:oauth_token]
|
37
|
-
key = oauth_token ? :hidden_by_user : :hidden_by_site
|
38
|
-
patch(key => hidden)
|
39
|
-
end
|
40
|
-
|
41
27
|
end
|
42
28
|
end
|
data/lib/the86-client/version.rb
CHANGED
data/spec/conversations_spec.rb
CHANGED
@@ -4,6 +4,10 @@ module The86::Client
|
|
4
4
|
|
5
5
|
describe "Conversations" do
|
6
6
|
|
7
|
+
let(:site) { The86::Client.site("test") }
|
8
|
+
let(:site_url) { "https://example.org/api/v1/sites/test" }
|
9
|
+
let(:conversations_url) { "#{site_url}/conversations" }
|
10
|
+
|
7
11
|
describe "listing conversations" do
|
8
12
|
it "returns empty array for site without conversations" do
|
9
13
|
expect_get_conversations(response_body: [])
|
@@ -24,7 +28,7 @@ module The86::Client
|
|
24
28
|
describe "creating conversations" do
|
25
29
|
it "posts and returns a conversation with the first post content" do
|
26
30
|
expect_request(
|
27
|
-
url:
|
31
|
+
url: conversations_url,
|
28
32
|
method: :post,
|
29
33
|
status: 201,
|
30
34
|
request_body: {content: "A new conversation."},
|
@@ -58,13 +62,45 @@ module The86::Client
|
|
58
62
|
end
|
59
63
|
end
|
60
64
|
|
61
|
-
|
62
|
-
|
65
|
+
describe "hiding and unhiding a conversation" do
|
66
|
+
let(:conversation) { site.conversations.build(id: 2) }
|
67
|
+
let(:oauth_url) { "#{conversations_url}/2" }
|
68
|
+
let(:basic_auth_url) { oauth_url.sub("//", "//user:pass@") }
|
69
|
+
let(:headers) { Hash.new }
|
70
|
+
def expectation(url, hidden_param)
|
71
|
+
{
|
72
|
+
url: url,
|
73
|
+
method: :patch,
|
74
|
+
status: 200,
|
75
|
+
request_body: hidden_param,
|
76
|
+
request_headers: headers,
|
77
|
+
response_body: {id: 2}.merge(hidden_param),
|
78
|
+
}
|
79
|
+
end
|
80
|
+
describe "without oauth" do
|
81
|
+
it "patches the conversation as hidden_by_site when no oauth_token" do
|
82
|
+
expect_request(expectation(basic_auth_url, hidden_by_site: true))
|
83
|
+
conversation.hide
|
84
|
+
|
85
|
+
expect_request(expectation(basic_auth_url, hidden_by_site: false))
|
86
|
+
conversation.unhide
|
87
|
+
end
|
88
|
+
end
|
89
|
+
describe "with oauth" do
|
90
|
+
let(:headers) { {"Authorization" => "Bearer secret"} }
|
91
|
+
it "patches the conversation as hidden_by_user when oauth_token present" do
|
92
|
+
expect_request(expectation(oauth_url, hidden_by_user: true))
|
93
|
+
conversation.hide(oauth_token: "secret")
|
94
|
+
|
95
|
+
expect_request(expectation(oauth_url, hidden_by_user: false))
|
96
|
+
conversation.unhide(oauth_token: "secret")
|
97
|
+
end
|
98
|
+
end
|
63
99
|
end
|
64
100
|
|
65
101
|
def expect_get_conversations(options)
|
66
102
|
expect_request({
|
67
|
-
url: "
|
103
|
+
url: conversations_url.sub("//", "//user:pass@"),
|
68
104
|
method: :get,
|
69
105
|
status: 200,
|
70
106
|
}.merge(options))
|
data/spec/posts_spec.rb
CHANGED
@@ -4,10 +4,19 @@ module The86::Client
|
|
4
4
|
|
5
5
|
describe Post do
|
6
6
|
|
7
|
+
let(:site) { The86::Client.site("test") }
|
8
|
+
let(:conversation) { Conversation.new(id: 32, site: site) }
|
9
|
+
let(:original_post) do
|
10
|
+
Post.new(id: 64, conversation: conversation, content: "Hello!")
|
11
|
+
end
|
12
|
+
let(:site_url) { "https://example.org/api/v1/sites/test" }
|
13
|
+
let(:conversation_url) { "#{site_url}/conversations/32" }
|
14
|
+
let(:posts_url) { "#{conversation_url}/posts" }
|
15
|
+
|
7
16
|
describe "replying to a post" do
|
8
17
|
it "sends in_reply_to_id" do
|
9
18
|
expect_request(
|
10
|
-
url:
|
19
|
+
url: posts_url,
|
11
20
|
method: :post,
|
12
21
|
status: 201,
|
13
22
|
request_body: {content: "Hi!", in_reply_to_id: 64},
|
@@ -37,7 +46,7 @@ module The86::Client
|
|
37
46
|
describe "following up to a conversation" do
|
38
47
|
it "creates new Post in the Conversation" do
|
39
48
|
expect_request(
|
40
|
-
url:
|
49
|
+
url: posts_url,
|
41
50
|
method: :post,
|
42
51
|
status: 201,
|
43
52
|
request_body: {content: "+1"},
|
@@ -54,68 +63,40 @@ module The86::Client
|
|
54
63
|
end
|
55
64
|
end
|
56
65
|
|
57
|
-
describe "
|
66
|
+
describe "hiding and unhiding posts" do
|
58
67
|
let(:post) { conversation.posts.build(id: 2) }
|
59
|
-
let(:
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
status: 200,
|
65
|
-
request_body: {hidden_by_site: true},
|
66
|
-
response_body: {id: 2, hidden_by_site: true},
|
67
|
-
)
|
68
|
-
post.hide
|
69
|
-
end
|
70
|
-
it "patches the post as hidden_by_user when oauth_token present" do
|
71
|
-
expect_request(
|
68
|
+
let(:oauth_url) { "#{posts_url}/2" }
|
69
|
+
let(:basic_auth_url) { oauth_url.sub("//", "//user:pass@") }
|
70
|
+
let(:headers) { Hash.new }
|
71
|
+
def expectation(url, hidden_param)
|
72
|
+
{
|
72
73
|
url: url,
|
73
74
|
method: :patch,
|
74
75
|
status: 200,
|
75
|
-
request_body:
|
76
|
-
request_headers:
|
77
|
-
response_body: {id: 2
|
78
|
-
|
79
|
-
post.hide(oauth_token: "secret")
|
76
|
+
request_body: hidden_param,
|
77
|
+
request_headers: headers,
|
78
|
+
response_body: {id: 2}.merge(hidden_param),
|
79
|
+
}
|
80
80
|
end
|
81
|
-
|
81
|
+
describe "without oauth" do
|
82
|
+
it "patches the post as hidden_by_site when no oauth_token" do
|
83
|
+
expect_request(expectation(basic_auth_url, hidden_by_site: true))
|
84
|
+
post.hide
|
82
85
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
it "patches the post as hidden_by_site when no oauth_token" do
|
87
|
-
expect_request(
|
88
|
-
url: url.sub("https://", "https://user:pass@"),
|
89
|
-
method: :patch,
|
90
|
-
status: 200,
|
91
|
-
request_body: {hidden_by_site: false},
|
92
|
-
response_body: {id: 2, hidden_by_site: false},
|
93
|
-
)
|
94
|
-
post.unhide
|
95
|
-
end
|
96
|
-
it "patches the post as hidden_by_user when oauth_token present" do
|
97
|
-
expect_request(
|
98
|
-
url: url,
|
99
|
-
method: :patch,
|
100
|
-
status: 200,
|
101
|
-
request_body: {hidden_by_user: false},
|
102
|
-
request_headers: {"Authorization" => "Bearer secret"},
|
103
|
-
response_body: {id: 2, hidden_by_site: false},
|
104
|
-
)
|
105
|
-
post.unhide(oauth_token: "secret")
|
86
|
+
expect_request(expectation(basic_auth_url, hidden_by_site: false))
|
87
|
+
post.unhide
|
88
|
+
end
|
106
89
|
end
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
90
|
+
describe "with oauth" do
|
91
|
+
let(:headers) { {"Authorization" => "Bearer secret"} }
|
92
|
+
it "patches the post as hidden_by_user when oauth_token present" do
|
93
|
+
expect_request(expectation(oauth_url, hidden_by_user: true))
|
94
|
+
post.hide(oauth_token: "secret")
|
112
95
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
def site
|
118
|
-
The86::Client.site("test")
|
96
|
+
expect_request(expectation(oauth_url, hidden_by_user: false))
|
97
|
+
post.unhide(oauth_token: "secret")
|
98
|
+
end
|
99
|
+
end
|
119
100
|
end
|
120
101
|
|
121
102
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: the86-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -203,6 +203,7 @@ files:
|
|
203
203
|
- lib/the86-client.rb
|
204
204
|
- lib/the86-client/access_token.rb
|
205
205
|
- lib/the86-client/active_model.rb
|
206
|
+
- lib/the86-client/can_be_hidden.rb
|
206
207
|
- lib/the86-client/connection.rb
|
207
208
|
- lib/the86-client/conversation.rb
|
208
209
|
- lib/the86-client/errors.rb
|