the86-client 1.1.0 → 1.3.2
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 +8 -6
- data/lib/the86-client/can_be_hidden.rb +1 -1
- data/lib/the86-client/connection.rb +15 -1
- data/lib/the86-client/conversation.rb +24 -1
- data/lib/the86-client/{site.rb → group.rb} +2 -2
- data/lib/the86-client/metadatum.rb +11 -0
- data/lib/the86-client/metadatum/conversation_metadatum.rb +8 -0
- data/lib/the86-client/post.rb +2 -0
- data/lib/the86-client/resource.rb +26 -8
- data/lib/the86-client/resource_collection.rb +5 -1
- data/lib/the86-client/version.rb +1 -1
- data/spec/conversations_spec.rb +55 -25
- data/spec/likes_spec.rb +4 -4
- data/spec/metadata_spec.rb +99 -0
- data/spec/post_spec.rb +9 -0
- data/spec/posts_spec.rb +7 -7
- data/spec/resource_spec.rb +37 -0
- metadata +45 -41
data/lib/the86-client.rb
CHANGED
@@ -10,10 +10,12 @@
|
|
10
10
|
can_be_hidden
|
11
11
|
access_token
|
12
12
|
user
|
13
|
-
|
13
|
+
group
|
14
14
|
post
|
15
15
|
conversation
|
16
16
|
like
|
17
|
+
metadatum
|
18
|
+
metadatum/conversation_metadatum
|
17
19
|
}.each { |r| require "the86-client/#{r}" }
|
18
20
|
|
19
21
|
module The86
|
@@ -21,17 +23,17 @@ module The86
|
|
21
23
|
|
22
24
|
# API entry points.
|
23
25
|
|
24
|
-
def self.
|
26
|
+
def self.groups
|
25
27
|
ResourceCollection.new(
|
26
28
|
Connection.new,
|
27
|
-
"
|
28
|
-
|
29
|
+
"groups",
|
30
|
+
Group,
|
29
31
|
nil
|
30
32
|
)
|
31
33
|
end
|
32
34
|
|
33
|
-
def self.
|
34
|
-
|
35
|
+
def self.group(slug)
|
36
|
+
Group.new(slug: slug)
|
35
37
|
end
|
36
38
|
|
37
39
|
def self.users
|
@@ -13,9 +13,16 @@ module The86
|
|
13
13
|
def faraday_adapter
|
14
14
|
@faraday_adapter || Faraday.default_adapter
|
15
15
|
end
|
16
|
+
|
16
17
|
end
|
17
18
|
|
19
|
+
attr_accessor :timeout, :open_timeout
|
20
|
+
|
18
21
|
def initialize
|
22
|
+
# Default some basic connection options
|
23
|
+
@timeout = 15 #seconds
|
24
|
+
@open_timeout = 3 #seconds
|
25
|
+
|
19
26
|
@faraday = Faraday.new(url) do |conn|
|
20
27
|
conn.request :json
|
21
28
|
conn.response :json
|
@@ -43,6 +50,10 @@ module The86
|
|
43
50
|
def post(options)
|
44
51
|
dispatch(:post, options)
|
45
52
|
end
|
53
|
+
|
54
|
+
def delete(options)
|
55
|
+
dispatch(:delete, options)
|
56
|
+
end
|
46
57
|
|
47
58
|
private
|
48
59
|
|
@@ -61,7 +72,10 @@ module The86
|
|
61
72
|
end
|
62
73
|
|
63
74
|
headers = @faraday.headers.merge(options[:headers] || {})
|
64
|
-
response = @faraday.run_request(method, path, data, headers)
|
75
|
+
response = @faraday.run_request(method, path, data, headers) do |req|
|
76
|
+
req.options[:timeout] = @timeout
|
77
|
+
req.options[:open_timeout] = @open_timeout
|
78
|
+
end
|
65
79
|
|
66
80
|
assert_http_status(response, options[:status])
|
67
81
|
|
@@ -5,13 +5,36 @@ module The86::Client
|
|
5
5
|
attribute :content, String # For creating new Conversation.
|
6
6
|
attribute :bumped_at, DateTime
|
7
7
|
attribute :created_at, DateTime
|
8
|
+
attribute :original_created_at, DateTime
|
8
9
|
attribute :updated_at, DateTime
|
9
10
|
|
10
11
|
path "conversations"
|
11
|
-
belongs_to :
|
12
|
+
belongs_to :group
|
12
13
|
has_many :posts, ->{ Post }
|
14
|
+
has_many :metadata, ->{ ConversationMetadatum }
|
15
|
+
|
16
|
+
accepts_nested_attributes_for :metadata
|
13
17
|
|
14
18
|
include CanBeHidden
|
15
19
|
|
20
|
+
def mute(attributes={})
|
21
|
+
unless attributes[:oauth_token]
|
22
|
+
raise Error, "Conversations must be hidden by a user"
|
23
|
+
end
|
24
|
+
self.oauth_token = attributes[:oauth_token]
|
25
|
+
connection.post(
|
26
|
+
path: resource_path << "/mute",
|
27
|
+
data: sendable_attributes,
|
28
|
+
status: 200
|
29
|
+
).data
|
30
|
+
end
|
31
|
+
|
32
|
+
def set_metadata(attributes={})
|
33
|
+
connection.patch(
|
34
|
+
path: resource_path << "/metadata",
|
35
|
+
data: attributes,
|
36
|
+
status: 204
|
37
|
+
)
|
38
|
+
end
|
16
39
|
end
|
17
40
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module The86::Client
|
2
|
-
class
|
2
|
+
class Group < Resource
|
3
3
|
|
4
4
|
attribute :id, Integer
|
5
5
|
attribute :name, String
|
@@ -7,7 +7,7 @@ module The86::Client
|
|
7
7
|
attribute :created_at, DateTime
|
8
8
|
attribute :updated_at, DateTime
|
9
9
|
|
10
|
-
path "
|
10
|
+
path "groups"
|
11
11
|
has_many :conversations, ->{ Conversation }
|
12
12
|
|
13
13
|
def url_id
|
data/lib/the86-client/post.rb
CHANGED
@@ -5,7 +5,9 @@ module The86::Client
|
|
5
5
|
attribute :content, String
|
6
6
|
attribute :content_html, String
|
7
7
|
attribute :in_reply_to_id, Integer
|
8
|
+
attribute :is_original, Boolean
|
8
9
|
attribute :created_at, DateTime
|
10
|
+
attribute :original_created_at, DateTime
|
9
11
|
attribute :updated_at, DateTime
|
10
12
|
|
11
13
|
path "posts"
|
@@ -23,7 +23,7 @@ module The86
|
|
23
23
|
end
|
24
24
|
|
25
25
|
# The name of the parent resource attribute.
|
26
|
-
# e.g: belongs_to :
|
26
|
+
# e.g: belongs_to :group
|
27
27
|
def belongs_to(name)
|
28
28
|
alias_method "#{name}=", :parent=
|
29
29
|
alias_method name, :parent
|
@@ -48,6 +48,11 @@ module The86
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
+
# Allow nested attribute creation
|
52
|
+
def accepts_nested_attributes_for(name)
|
53
|
+
attribute name, Array
|
54
|
+
end
|
55
|
+
|
51
56
|
end
|
52
57
|
|
53
58
|
##
|
@@ -70,6 +75,14 @@ module The86
|
|
70
75
|
"%s/%s" % [ self.class.collection_path(@parent), url_id ]
|
71
76
|
end
|
72
77
|
|
78
|
+
# TODO: The parent resource should be appropriately updated that the resource no longer exists
|
79
|
+
def delete!
|
80
|
+
connection.delete(
|
81
|
+
path: resource_path,
|
82
|
+
status: 204
|
83
|
+
).data
|
84
|
+
end
|
85
|
+
|
73
86
|
def save
|
74
87
|
id ? save_existing : save_new
|
75
88
|
end
|
@@ -130,13 +143,18 @@ module The86
|
|
130
143
|
end
|
131
144
|
|
132
145
|
def has_many_reader(name, class_proc)
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
146
|
+
variable_name = "@_has_many_reader_#{name}"
|
147
|
+
instance_variable_get(variable_name) ||
|
148
|
+
instance_variable_set(variable_name, (
|
149
|
+
klass = class_proc.call
|
150
|
+
ResourceCollection.new(
|
151
|
+
connection,
|
152
|
+
klass.collection_path(self),
|
153
|
+
class_proc.call,
|
154
|
+
self,
|
155
|
+
(@_has_many || {})[name] || nil
|
156
|
+
)
|
157
|
+
)
|
140
158
|
)
|
141
159
|
rescue KeyError
|
142
160
|
raise Error, "No reference to children :#{name}"
|
@@ -60,7 +60,7 @@ module The86::Client
|
|
60
60
|
end
|
61
61
|
|
62
62
|
# Load the next page of records, based on the pagination header, e.g.
|
63
|
-
# Link: <http://example.org/api/v1/
|
63
|
+
# Link: <http://example.org/api/v1/groups/a/conversations?bumped_before=time>; rel="next"
|
64
64
|
def more
|
65
65
|
if more?
|
66
66
|
url = Addressable::URI.parse(http_response.links[:next])
|
@@ -93,6 +93,10 @@ module The86::Client
|
|
93
93
|
to_a[index]
|
94
94
|
end
|
95
95
|
|
96
|
+
def << record
|
97
|
+
(@records || []) << record
|
98
|
+
end
|
99
|
+
|
96
100
|
private
|
97
101
|
|
98
102
|
def http_response
|
data/lib/the86-client/version.rb
CHANGED
data/spec/conversations_spec.rb
CHANGED
@@ -4,24 +4,24 @@ module The86::Client
|
|
4
4
|
|
5
5
|
describe "Conversations" do
|
6
6
|
|
7
|
-
let(:
|
8
|
-
let(:
|
9
|
-
let(:conversations_url) { "#{
|
7
|
+
let(:group) { The86::Client.group("test") }
|
8
|
+
let(:group_url) { "https://example.org/api/v1/groups/test" }
|
9
|
+
let(:conversations_url) { "#{group_url}/conversations" }
|
10
10
|
|
11
11
|
describe "listing conversations" do
|
12
|
-
it "returns empty array for
|
12
|
+
it "returns empty array for group without conversations" do
|
13
13
|
expect_get_conversations(response_body: [])
|
14
|
-
|
14
|
+
group.conversations.to_a.size.must_equal 0
|
15
15
|
end
|
16
16
|
|
17
17
|
it "returns collection of conversations" do
|
18
18
|
expect_get_conversations(response_body: [{id: 10}, {id: 12}])
|
19
|
-
conversations =
|
19
|
+
conversations = group.conversations
|
20
20
|
conversations.to_a.size.must_equal 2
|
21
21
|
c = conversations.first
|
22
22
|
c.must_be_instance_of Conversation
|
23
23
|
c.id.must_equal 10
|
24
|
-
c.
|
24
|
+
c.group.must_equal group
|
25
25
|
end
|
26
26
|
|
27
27
|
it "sends posts_since parameter" do
|
@@ -29,12 +29,12 @@ module The86::Client
|
|
29
29
|
response_body: [{id: 10}, {id: 12}],
|
30
30
|
parameters: {posts_since: "time"}
|
31
31
|
)
|
32
|
-
conversations =
|
32
|
+
conversations = group.conversations.with_parameters(posts_since: "time")
|
33
33
|
conversations.to_a.size.must_equal 2
|
34
34
|
c = conversations.first
|
35
35
|
c.must_be_instance_of Conversation
|
36
36
|
c.id.must_equal 10
|
37
|
-
c.
|
37
|
+
c.group.must_equal group
|
38
38
|
end
|
39
39
|
|
40
40
|
it "handles pagination headers" do
|
@@ -49,7 +49,7 @@ module The86::Client
|
|
49
49
|
url: basic_auth_url(next_url),
|
50
50
|
response_body: [{id: 3}, {id: 4}],
|
51
51
|
)
|
52
|
-
page1 =
|
52
|
+
page1 = group.conversations.with_parameters(limit: 2)
|
53
53
|
page1.more?.must_equal true
|
54
54
|
|
55
55
|
page2 = page1.more
|
@@ -74,9 +74,9 @@ module The86::Client
|
|
74
74
|
)
|
75
75
|
|
76
76
|
# Emulate parameters being serialized & stored for a later request.
|
77
|
-
page1 =
|
77
|
+
page1 = group.conversations.with_parameters(limit: 2)
|
78
78
|
parameters = JSON.parse(JSON.generate(page1.more.parameters))
|
79
|
-
page2 =
|
79
|
+
page2 = group.conversations.with_parameters(parameters)
|
80
80
|
|
81
81
|
parameters.must_equal("limit" => "2", "bumped_before" => "timestamp")
|
82
82
|
|
@@ -90,19 +90,22 @@ module The86::Client
|
|
90
90
|
|
91
91
|
describe "creating conversations" do
|
92
92
|
it "posts and returns a conversation with the first post content" do
|
93
|
+
|
94
|
+
c = group.conversations.build(
|
95
|
+
content: "A new conversation.",
|
96
|
+
oauth_token: "secrettoken",
|
97
|
+
)
|
98
|
+
|
93
99
|
expect_request(
|
94
100
|
url: conversations_url,
|
95
101
|
method: :post,
|
96
102
|
status: 201,
|
97
|
-
request_body: {content: "A new conversation."},
|
103
|
+
request_body: {content: "A new conversation.", metadata: c.metadata.to_s},
|
98
104
|
response_body: {id: 2, posts: [{id: 5, content: "A new conversation."}]},
|
99
105
|
request_headers: {"Authorization" => "Bearer secrettoken"},
|
100
106
|
)
|
101
107
|
|
102
|
-
c
|
103
|
-
content: "A new conversation.",
|
104
|
-
oauth_token: "secrettoken",
|
105
|
-
)
|
108
|
+
c.save
|
106
109
|
|
107
110
|
c.id.must_equal 2
|
108
111
|
posts = c.posts
|
@@ -114,22 +117,22 @@ module The86::Client
|
|
114
117
|
describe "finding a conversation" do
|
115
118
|
it "gets the conversation, loads data into the resource" do
|
116
119
|
expect_request(
|
117
|
-
url: basic_auth_url("https://example.org/api/v1/
|
120
|
+
url: basic_auth_url("https://example.org/api/v1/groups/test/conversations/4"),
|
118
121
|
method: :get,
|
119
122
|
status: 200,
|
120
123
|
response_body: {id: 4, posts: [{id: 8, content: "A post."}]},
|
121
124
|
)
|
122
|
-
c =
|
125
|
+
c = group.conversations.find(4)
|
123
126
|
c.id.must_equal 4
|
124
127
|
c.posts.first.content.must_equal "A post."
|
125
128
|
end
|
126
129
|
end
|
127
130
|
|
128
131
|
describe "hiding and unhiding a conversation" do
|
129
|
-
let(:conversation) {
|
132
|
+
let(:conversation) { group.conversations.build(id: 2) }
|
130
133
|
let(:user_auth_url) { "#{conversations_url}/2" }
|
131
|
-
let(:
|
132
|
-
let(:
|
134
|
+
let(:group_auth_url) { user_auth_url.sub("//", "//user:pass@") }
|
135
|
+
let(:group_auth_url) { basic_auth_url(user_auth_url) }
|
133
136
|
let(:headers) { Hash.new }
|
134
137
|
def expectation(url, hidden_param)
|
135
138
|
{
|
@@ -142,11 +145,11 @@ module The86::Client
|
|
142
145
|
}
|
143
146
|
end
|
144
147
|
describe "without oauth" do
|
145
|
-
it "patches the conversation as
|
146
|
-
expect_request(expectation(
|
148
|
+
it "patches the conversation as hidden_by_group when no oauth_token" do
|
149
|
+
expect_request(expectation(group_auth_url, hidden_by_group: true))
|
147
150
|
conversation.hide
|
148
151
|
|
149
|
-
expect_request(expectation(
|
152
|
+
expect_request(expectation(group_auth_url, hidden_by_group: false))
|
150
153
|
conversation.unhide
|
151
154
|
end
|
152
155
|
end
|
@@ -162,6 +165,33 @@ module The86::Client
|
|
162
165
|
end
|
163
166
|
end
|
164
167
|
|
168
|
+
describe "muting a conversation" do
|
169
|
+
let(:conversation) { group.conversations.build(id: 2) }
|
170
|
+
describe "without oauth" do
|
171
|
+
it "raises an error" do
|
172
|
+
->{ conversation.mute }.must_raise Error
|
173
|
+
end
|
174
|
+
end
|
175
|
+
describe "with oauth" do
|
176
|
+
def expectation(url, hidden_param={})
|
177
|
+
{
|
178
|
+
url: url,
|
179
|
+
method: :post,
|
180
|
+
status: 200,
|
181
|
+
request_body: hidden_param,
|
182
|
+
request_headers: headers,
|
183
|
+
response_body: {id: 2}.merge(hidden_param),
|
184
|
+
}
|
185
|
+
end
|
186
|
+
let(:mute_url) { "#{conversations_url}/2/mute" }
|
187
|
+
let(:headers) { {"Authorization" => "Bearer secret"} }
|
188
|
+
it "mutes the conversation" do
|
189
|
+
expect_request(expectation(mute_url))
|
190
|
+
conversation.mute(oauth_token: "secret")
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
165
195
|
def expect_get_conversations(options)
|
166
196
|
expect_request({
|
167
197
|
url: basic_auth_url(conversations_url),
|
data/spec/likes_spec.rb
CHANGED
@@ -4,10 +4,10 @@ module The86::Client
|
|
4
4
|
|
5
5
|
describe Like do
|
6
6
|
|
7
|
-
let(:
|
8
|
-
let(:
|
9
|
-
let(:post) {
|
10
|
-
let(:likes_url) { "#{
|
7
|
+
let(:group) { The86::Client.group("test") }
|
8
|
+
let(:group_url) { "https://example.org/api/v1/groups/test" }
|
9
|
+
let(:post) { group.conversations.build(id: 1).posts.build(id: 2) }
|
10
|
+
let(:likes_url) { "#{group_url}/conversations/1/posts/2/likes" }
|
11
11
|
|
12
12
|
it "POSTs a new Like" do
|
13
13
|
expect_request(
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
module The86::Client
|
4
|
+
|
5
|
+
describe ConversationMetadatum do
|
6
|
+
|
7
|
+
let(:group) { The86::Client.group("test") }
|
8
|
+
let(:group_url) { "https://example.org/api/v1/groups/test" }
|
9
|
+
let(:conversation) { group.conversations.build(id: 1) }
|
10
|
+
let(:metadata_url) { "#{group_url}/conversations/1/metadata" }
|
11
|
+
|
12
|
+
it "POSTs a new metadatum" do
|
13
|
+
expect_request(
|
14
|
+
url: metadata_url,
|
15
|
+
method: :post,
|
16
|
+
status: 201,
|
17
|
+
request_body: { key: "foo", value: "bar" },
|
18
|
+
response_body: { key: "foo", value: "bar" },
|
19
|
+
request_headers: {"Authorization" => "Bearer secret"},
|
20
|
+
)
|
21
|
+
|
22
|
+
m = conversation.metadata.create(key: "foo", value: "bar", oauth_token: "secret")
|
23
|
+
|
24
|
+
m.must_be_instance_of ConversationMetadatum
|
25
|
+
m.key.must_equal "foo"
|
26
|
+
m.value.must_equal "bar"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "GETs metadata" do
|
30
|
+
expect_request(
|
31
|
+
url: metadata_url.sub("//", "//user:pass@"),
|
32
|
+
method: :get,
|
33
|
+
status: 200,
|
34
|
+
response_body: [
|
35
|
+
{ key: "tag", value: "foo" },
|
36
|
+
{ key: "tag", value: "bar" },
|
37
|
+
],
|
38
|
+
)
|
39
|
+
|
40
|
+
conversation.metadata.map(&:value).must_equal %w{ foo bar }
|
41
|
+
end
|
42
|
+
|
43
|
+
it "DELETEs a metadatum" do
|
44
|
+
metadata_auth_url = metadata_url.sub("//", "//user:pass@")
|
45
|
+
|
46
|
+
expect_request(
|
47
|
+
url: metadata_auth_url,
|
48
|
+
method: :get,
|
49
|
+
status: 200,
|
50
|
+
response_body: [
|
51
|
+
{ id: "1", key: "tag", value: "foo" },
|
52
|
+
{ id: "2", key: "tag", value: "bar" },
|
53
|
+
],
|
54
|
+
)
|
55
|
+
|
56
|
+
m = conversation.metadata
|
57
|
+
|
58
|
+
expect_request(
|
59
|
+
url: "#{metadata_auth_url}/#{m.first.id}",
|
60
|
+
method: :delete,
|
61
|
+
status: 204)
|
62
|
+
|
63
|
+
m.first.delete!
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe Conversation do
|
68
|
+
let(:group) { The86::Client.group("test") }
|
69
|
+
let(:group_url) { "https://example.org/api/v1/groups/test" }
|
70
|
+
let(:conversation) { group.conversations.build(id: 1) }
|
71
|
+
let(:metadata_url) { "#{group_url}/conversations/1/metadata" }
|
72
|
+
|
73
|
+
it "PATCHes metadata for a given key" do
|
74
|
+
metadata_auth_url = metadata_url.sub("//", "//user:pass@")
|
75
|
+
|
76
|
+
expect_request(
|
77
|
+
url: metadata_auth_url,
|
78
|
+
method: :patch,
|
79
|
+
status: 204,
|
80
|
+
request_body: { key: ["a", "b", "c"] },
|
81
|
+
)
|
82
|
+
|
83
|
+
conversation.set_metadata({ key: ["a", "b", "c"]})
|
84
|
+
end
|
85
|
+
|
86
|
+
it "clears a key by sending an empty array" do
|
87
|
+
metadata_auth_url = metadata_url.sub("//", "//user:pass@")
|
88
|
+
|
89
|
+
expect_request(
|
90
|
+
url: metadata_auth_url,
|
91
|
+
method: :patch,
|
92
|
+
status: 204,
|
93
|
+
request_body: { key: [] },
|
94
|
+
)
|
95
|
+
|
96
|
+
conversation.set_metadata({key: []})
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/spec/post_spec.rb
CHANGED
@@ -12,6 +12,15 @@ module The86::Client
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
describe "is_original?" do
|
16
|
+
it "is true when is_original is true" do
|
17
|
+
Post.new(is_original: true).is_original?.must_equal true
|
18
|
+
end
|
19
|
+
it "is false when is_original is false" do
|
20
|
+
Post.new(is_original: false).is_original?.must_equal false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
15
24
|
describe "#user" do
|
16
25
|
let(:post) { Post.new(id: 1, user: {id: 2, name: "John Citizen"}) }
|
17
26
|
it "returns instance of The86::Client::User" do
|
data/spec/posts_spec.rb
CHANGED
@@ -4,13 +4,13 @@ module The86::Client
|
|
4
4
|
|
5
5
|
describe Post do
|
6
6
|
|
7
|
-
let(:
|
8
|
-
let(:conversation) { Conversation.new(id: 32,
|
7
|
+
let(:group) { The86::Client.group("test") }
|
8
|
+
let(:conversation) { Conversation.new(id: 32, group: group) }
|
9
9
|
let(:original_post) do
|
10
10
|
Post.new(id: 64, conversation: conversation, content: "Hello!")
|
11
11
|
end
|
12
|
-
let(:
|
13
|
-
let(:conversation_url) { "#{
|
12
|
+
let(:group_url) { "https://example.org/api/v1/groups/test" }
|
13
|
+
let(:conversation_url) { "#{group_url}/conversations/32" }
|
14
14
|
let(:posts_url) { "#{conversation_url}/posts" }
|
15
15
|
|
16
16
|
describe "replying to a post" do
|
@@ -79,11 +79,11 @@ module The86::Client
|
|
79
79
|
}
|
80
80
|
end
|
81
81
|
describe "without oauth" do
|
82
|
-
it "patches the post as
|
83
|
-
expect_request(expectation(basic_auth_url,
|
82
|
+
it "patches the post as hidden_by_group when no oauth_token" do
|
83
|
+
expect_request(expectation(basic_auth_url, hidden_by_group: true))
|
84
84
|
post.hide
|
85
85
|
|
86
|
-
expect_request(expectation(basic_auth_url,
|
86
|
+
expect_request(expectation(basic_auth_url, hidden_by_group: false))
|
87
87
|
post.unhide
|
88
88
|
end
|
89
89
|
end
|
data/spec/resource_spec.rb
CHANGED
@@ -32,5 +32,42 @@ module The86::Client
|
|
32
32
|
resource.new(id: 1, code: "A").wont_equal false
|
33
33
|
end
|
34
34
|
end
|
35
|
+
|
36
|
+
describe "#has_many" do
|
37
|
+
it "returns the same instance of ResourceCollection" do
|
38
|
+
class Widget < Resource
|
39
|
+
attribute :name, String
|
40
|
+
end
|
41
|
+
resource = Class.new(Resource) do
|
42
|
+
attribute :id, Integer
|
43
|
+
has_many :widgets, ->{ Widget }
|
44
|
+
end
|
45
|
+
i = resource.new widgets: [{ name: "Knob" }]
|
46
|
+
widgets = i.widgets
|
47
|
+
widgets.send(:records).size.must_equal 1
|
48
|
+
i.widgets << Widget.new(name: "Flange")
|
49
|
+
widgets.send(:records).size.must_equal 2
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#accepts_nested_attributes_for" do
|
54
|
+
class Widget < Resource
|
55
|
+
attribute :name, String
|
56
|
+
end
|
57
|
+
|
58
|
+
resource = Class.new(Resource) do
|
59
|
+
attribute :id, Integer
|
60
|
+
has_many :widgets, -> { Widget }
|
61
|
+
accepts_nested_attributes_for :widgets
|
62
|
+
end
|
63
|
+
|
64
|
+
it "includes nested items" do
|
65
|
+
resource.
|
66
|
+
new(id: 123, widgets: [{ name: "Knob" }, { name: "Flange" }]).
|
67
|
+
sendable_attributes[:widgets].
|
68
|
+
map{|widget| widget.attributes }.
|
69
|
+
must_equal([{ name: "Knob" }, { name: "Flange" }])
|
70
|
+
end
|
71
|
+
end
|
35
72
|
end
|
36
73
|
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: 1.
|
4
|
+
version: 1.3.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,200 +9,200 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
16
|
+
prerelease: false
|
16
17
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '0'
|
22
|
+
none: false
|
22
23
|
type: :runtime
|
23
|
-
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
25
|
requirements:
|
27
26
|
- - ! '>='
|
28
27
|
- !ruby/object:Gem::Version
|
29
28
|
version: '0'
|
29
|
+
none: false
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: faraday_middleware
|
32
|
+
prerelease: false
|
32
33
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
34
|
requirements:
|
35
35
|
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
37
|
version: '0'
|
38
|
+
none: false
|
38
39
|
type: :runtime
|
39
|
-
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
41
|
requirements:
|
43
42
|
- - ! '>='
|
44
43
|
- !ruby/object:Gem::Version
|
45
44
|
version: '0'
|
45
|
+
none: false
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: hashie
|
48
|
+
prerelease: false
|
48
49
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
50
|
requirements:
|
51
51
|
- - ! '>='
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
|
+
none: false
|
54
55
|
type: :runtime
|
55
|
-
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
57
|
requirements:
|
59
58
|
- - ! '>='
|
60
59
|
- !ruby/object:Gem::Version
|
61
60
|
version: '0'
|
61
|
+
none: false
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: addressable
|
64
|
+
prerelease: false
|
64
65
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
66
|
requirements:
|
67
67
|
- - ! '>='
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
|
+
none: false
|
70
71
|
type: :runtime
|
71
|
-
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
73
|
requirements:
|
75
74
|
- - ! '>='
|
76
75
|
- !ruby/object:Gem::Version
|
77
76
|
version: '0'
|
77
|
+
none: false
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
79
|
name: virtus
|
80
|
+
prerelease: false
|
80
81
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
82
|
requirements:
|
83
83
|
- - ! '>='
|
84
84
|
- !ruby/object:Gem::Version
|
85
85
|
version: '0'
|
86
|
+
none: false
|
86
87
|
type: :runtime
|
87
|
-
prerelease: false
|
88
88
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
89
|
requirements:
|
91
90
|
- - ! '>='
|
92
91
|
- !ruby/object:Gem::Version
|
93
92
|
version: '0'
|
93
|
+
none: false
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
95
|
name: guard
|
96
|
+
prerelease: false
|
96
97
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
98
|
requirements:
|
99
99
|
- - ! '>='
|
100
100
|
- !ruby/object:Gem::Version
|
101
101
|
version: '0'
|
102
|
+
none: false
|
102
103
|
type: :development
|
103
|
-
prerelease: false
|
104
104
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
105
|
requirements:
|
107
106
|
- - ! '>='
|
108
107
|
- !ruby/object:Gem::Version
|
109
108
|
version: '0'
|
109
|
+
none: false
|
110
110
|
- !ruby/object:Gem::Dependency
|
111
111
|
name: guard-minitest
|
112
|
+
prerelease: false
|
112
113
|
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
114
|
requirements:
|
115
115
|
- - ! '>='
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
|
+
none: false
|
118
119
|
type: :development
|
119
|
-
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
121
|
requirements:
|
123
122
|
- - ! '>='
|
124
123
|
- !ruby/object:Gem::Version
|
125
124
|
version: '0'
|
125
|
+
none: false
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
127
|
name: minitest
|
128
|
+
prerelease: false
|
128
129
|
requirement: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
130
|
requirements:
|
131
131
|
- - ! '>='
|
132
132
|
- !ruby/object:Gem::Version
|
133
133
|
version: '0'
|
134
|
+
none: false
|
134
135
|
type: :development
|
135
|
-
prerelease: false
|
136
136
|
version_requirements: !ruby/object:Gem::Requirement
|
137
|
-
none: false
|
138
137
|
requirements:
|
139
138
|
- - ! '>='
|
140
139
|
- !ruby/object:Gem::Version
|
141
140
|
version: '0'
|
141
|
+
none: false
|
142
142
|
- !ruby/object:Gem::Dependency
|
143
143
|
name: ansi
|
144
|
+
prerelease: false
|
144
145
|
requirement: !ruby/object:Gem::Requirement
|
145
|
-
none: false
|
146
146
|
requirements:
|
147
147
|
- - ! '>='
|
148
148
|
- !ruby/object:Gem::Version
|
149
149
|
version: '0'
|
150
|
+
none: false
|
150
151
|
type: :development
|
151
|
-
prerelease: false
|
152
152
|
version_requirements: !ruby/object:Gem::Requirement
|
153
|
-
none: false
|
154
153
|
requirements:
|
155
154
|
- - ! '>='
|
156
155
|
- !ruby/object:Gem::Version
|
157
156
|
version: '0'
|
157
|
+
none: false
|
158
158
|
- !ruby/object:Gem::Dependency
|
159
159
|
name: turn
|
160
|
+
prerelease: false
|
160
161
|
requirement: !ruby/object:Gem::Requirement
|
161
|
-
none: false
|
162
162
|
requirements:
|
163
163
|
- - ! '>='
|
164
164
|
- !ruby/object:Gem::Version
|
165
165
|
version: '0'
|
166
|
+
none: false
|
166
167
|
type: :development
|
167
|
-
prerelease: false
|
168
168
|
version_requirements: !ruby/object:Gem::Requirement
|
169
|
-
none: false
|
170
169
|
requirements:
|
171
170
|
- - ! '>='
|
172
171
|
- !ruby/object:Gem::Version
|
173
172
|
version: '0'
|
173
|
+
none: false
|
174
174
|
- !ruby/object:Gem::Dependency
|
175
175
|
name: rake
|
176
|
+
prerelease: false
|
176
177
|
requirement: !ruby/object:Gem::Requirement
|
177
|
-
none: false
|
178
178
|
requirements:
|
179
179
|
- - ! '>='
|
180
180
|
- !ruby/object:Gem::Version
|
181
181
|
version: '0'
|
182
|
+
none: false
|
182
183
|
type: :development
|
183
|
-
prerelease: false
|
184
184
|
version_requirements: !ruby/object:Gem::Requirement
|
185
|
-
none: false
|
186
185
|
requirements:
|
187
186
|
- - ! '>='
|
188
187
|
- !ruby/object:Gem::Version
|
189
188
|
version: '0'
|
189
|
+
none: false
|
190
190
|
- !ruby/object:Gem::Dependency
|
191
191
|
name: webmock
|
192
|
+
prerelease: false
|
192
193
|
requirement: !ruby/object:Gem::Requirement
|
193
|
-
none: false
|
194
194
|
requirements:
|
195
195
|
- - ! '>='
|
196
196
|
- !ruby/object:Gem::Version
|
197
197
|
version: '0'
|
198
|
+
none: false
|
198
199
|
type: :development
|
199
|
-
prerelease: false
|
200
200
|
version_requirements: !ruby/object:Gem::Requirement
|
201
|
-
none: false
|
202
201
|
requirements:
|
203
202
|
- - ! '>='
|
204
203
|
- !ruby/object:Gem::Version
|
205
204
|
version: '0'
|
205
|
+
none: false
|
206
206
|
description: Client for The 86 conversation API server
|
207
207
|
email:
|
208
208
|
- paul@sitepoint.com
|
@@ -223,17 +223,20 @@ files:
|
|
223
223
|
- lib/the86-client/connection.rb
|
224
224
|
- lib/the86-client/conversation.rb
|
225
225
|
- lib/the86-client/errors.rb
|
226
|
+
- lib/the86-client/group.rb
|
226
227
|
- lib/the86-client/like.rb
|
228
|
+
- lib/the86-client/metadatum.rb
|
229
|
+
- lib/the86-client/metadatum/conversation_metadatum.rb
|
227
230
|
- lib/the86-client/oauth_bearer_authorization.rb
|
228
231
|
- lib/the86-client/post.rb
|
229
232
|
- lib/the86-client/resource.rb
|
230
233
|
- lib/the86-client/resource_collection.rb
|
231
234
|
- lib/the86-client/response.rb
|
232
|
-
- lib/the86-client/site.rb
|
233
235
|
- lib/the86-client/user.rb
|
234
236
|
- lib/the86-client/version.rb
|
235
237
|
- spec/conversations_spec.rb
|
236
238
|
- spec/likes_spec.rb
|
239
|
+
- spec/metadata_spec.rb
|
237
240
|
- spec/oauth_bearer_authorization_spec.rb
|
238
241
|
- spec/post_spec.rb
|
239
242
|
- spec/posts_spec.rb
|
@@ -251,17 +254,17 @@ rdoc_options: []
|
|
251
254
|
require_paths:
|
252
255
|
- lib
|
253
256
|
required_ruby_version: !ruby/object:Gem::Requirement
|
254
|
-
none: false
|
255
257
|
requirements:
|
256
258
|
- - ! '>='
|
257
259
|
- !ruby/object:Gem::Version
|
258
260
|
version: '0'
|
259
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
260
261
|
none: false
|
262
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
261
263
|
requirements:
|
262
264
|
- - ! '>='
|
263
265
|
- !ruby/object:Gem::Version
|
264
266
|
version: '0'
|
267
|
+
none: false
|
265
268
|
requirements: []
|
266
269
|
rubyforge_project:
|
267
270
|
rubygems_version: 1.8.23
|
@@ -271,6 +274,7 @@ summary: Exposes The 86 conversation API server as an object model.
|
|
271
274
|
test_files:
|
272
275
|
- spec/conversations_spec.rb
|
273
276
|
- spec/likes_spec.rb
|
277
|
+
- spec/metadata_spec.rb
|
274
278
|
- spec/oauth_bearer_authorization_spec.rb
|
275
279
|
- spec/post_spec.rb
|
276
280
|
- spec/posts_spec.rb
|