adn 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.travis.yml +1 -0
- data/CHANGELOG.md +3 -1
- data/Gemfile +3 -2
- data/Gemfile.lock +5 -5
- data/README.md +5 -5
- data/Rakefile +1 -8
- data/adn.gemspec +1 -1
- data/lib/adn/api/message.rb +23 -0
- data/lib/adn/api/response.rb +5 -1
- data/lib/adn/api.rb +6 -4
- data/lib/adn/constants.rb +3 -0
- data/lib/adn/message.rb +67 -0
- data/lib/adn/post.rb +6 -1
- data/lib/adn/recipes.rb +37 -0
- data/lib/adn/user.rb +1 -1
- data/lib/adn/version.rb +1 -1
- data/lib/adn.rb +3 -1
- data/spec/adn/api/message_spec.rb +61 -0
- data/spec/adn/api/post_spec.rb +17 -0
- data/spec/adn/api/response_spec.rb +2 -2
- data/spec/adn/message_spec.rb +124 -0
- data/spec/adn_spec.rb +2 -1
- data/spec/spec_helper.rb +1 -1
- metadata +15 -13
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 06ed1a97a3c6eb2616915eacbd453390e0a98b12
|
4
|
+
data.tar.gz: 89dbc49b0cb184307fad22cfa5490d4a31897c99
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 480a7313ea2b43093fd15c8868dd960513ee2a0446c92db23bd2d86bab3eed6c646c7127822eb74d81e5db88f8d4a8be31850ce6c0ca4d68ef0541045c152e9c
|
7
|
+
data.tar.gz: f0d46825fbadf266d8acd5426e924b92c2f626263c91b4dc81c82af4e82dd9c7062cfc30ad80f5aceb44290dd727cb182b074355c0c51822c38b0fc5cf20ae16
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
### Changelog
|
2
2
|
|
3
|
+
* **Version 0.3.5** (11 December 2013)
|
4
|
+
* Added recipe for easy broadcast creation
|
3
5
|
* **Version 0.3.5** (23 October 2012)
|
4
|
-
|
6
|
+
* Added the unified stream
|
5
7
|
* **Version 0.3.1** (28 August 2012)
|
6
8
|
* Fixed naming conflict.
|
7
9
|
* **Version 0.3** (28 August 2012)
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
adn (0.3.
|
4
|
+
adn (0.3.6)
|
5
5
|
|
6
6
|
GEM
|
7
|
-
remote:
|
7
|
+
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
minitest (
|
10
|
-
rake (
|
9
|
+
minitest (5.1.0)
|
10
|
+
rake (10.1.0)
|
11
11
|
|
12
12
|
PLATFORMS
|
13
13
|
ruby
|
14
14
|
|
15
15
|
DEPENDENCIES
|
16
16
|
adn!
|
17
|
-
minitest (~>
|
17
|
+
minitest (~> 5.1)
|
18
18
|
rake
|
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
ADN
|
2
2
|
===
|
3
3
|
|
4
|
-
[![Build Status](https://
|
4
|
+
[![Build Status](https://api.travis-ci.org/adn-rb/adn.png)](https://travis-ci.org/adn-rb/adn)
|
5
5
|
|
6
|
-
A Ruby library for App.net by [@kishyr](https://alpha.app.net/kishyr).
|
6
|
+
A Ruby library for App.net by [@kishyr](https://alpha.app.net/kishyr).
|
7
7
|
|
8
|
-
This library follows the current [App.net API Spec](https://github.com/appdotnet/api-spec) (as at 26 August 2012).
|
8
|
+
This library follows the current [App.net API Spec](https://github.com/appdotnet/api-spec) (as at 26 August 2012).
|
9
9
|
|
10
10
|
### Contributors
|
11
11
|
|
@@ -26,7 +26,7 @@ Or you can install ADN directly from rubygems.org:
|
|
26
26
|
`gem install adn`
|
27
27
|
|
28
28
|
### Usage
|
29
|
-
For API calls that accept parameters described in the App.net API Spec, simply pass them as a dictionary to the method.
|
29
|
+
For API calls that accept parameters described in the App.net API Spec, simply pass them as a dictionary to the method.
|
30
30
|
|
31
31
|
```ruby
|
32
32
|
require 'adn'
|
@@ -41,7 +41,7 @@ Complete documentation will be available soon, but in the meantime you can brows
|
|
41
41
|
|
42
42
|
### License
|
43
43
|
|
44
|
-
**ADN** is licensed under the MIT License and is Copyright (c)
|
44
|
+
**ADN** is licensed under the MIT License and is Copyright (c) 2013 Kishyr Ramdial.
|
45
45
|
|
46
46
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
47
47
|
|
data/Rakefile
CHANGED
@@ -14,11 +14,4 @@ task :quality do
|
|
14
14
|
Bundler.with_clean_env do
|
15
15
|
exec 'cane'
|
16
16
|
end
|
17
|
-
end
|
18
|
-
|
19
|
-
desc "Run tests in a loop using kicker (>= 3.0.0pre1)"
|
20
|
-
task :kicker do
|
21
|
-
Bundler.with_clean_env do
|
22
|
-
exec 'kicker --no-notification -r ruby -e "clear && rake" spec lib'
|
23
|
-
end
|
24
|
-
end
|
17
|
+
end
|
data/adn.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.email = ["kishyr@gmail.com", "buddhamagnet@gmail.com", "peter@c7.se"]
|
10
10
|
s.description = "A simple and easy to use library to interact with App.net's API"
|
11
11
|
s.summary = "A Ruby library for App.net"
|
12
|
-
s.homepage = "https://github.com/
|
12
|
+
s.homepage = "https://github.com/adn-rb/adn"
|
13
13
|
s.files = `git ls-files`.split($\)
|
14
14
|
s.test_files = s.files.grep(%r{^(spec)/})
|
15
15
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module ADN
|
4
|
+
module API
|
5
|
+
module Message
|
6
|
+
def self.create(channel_id, params)
|
7
|
+
ADN::API.post("#{ADN::API_ENDPOINT_CHANNELS}/#{channel_id}/messages", params)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.retrieve(channel_id, message_id)
|
11
|
+
ADN::API.get("#{ADN::API_ENDPOINT_CHANNELS}/#{channel_id}/messages/#{message_id}")
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.by_id(channel_id, message_id)
|
15
|
+
self.retrieve(channel_id, message_id)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.delete(channel_id, message_id)
|
19
|
+
ADN::API.delete("#{ADN::API_ENDPOINT_CHANNELS}/#{channel_id}/messages/#{message_id}")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/adn/api/response.rb
CHANGED
@@ -6,7 +6,11 @@ module ADN
|
|
6
6
|
module API
|
7
7
|
class Response < SimpleDelegator
|
8
8
|
def has_error?
|
9
|
-
|
9
|
+
self['meta'].nil? || self['meta']['code'].nil? || self['meta']['code'] >= HTTP_ERROR
|
10
|
+
end
|
11
|
+
|
12
|
+
def error_message
|
13
|
+
self.fetch('meta').fetch('error_message')
|
10
14
|
end
|
11
15
|
end
|
12
16
|
end
|
data/lib/adn/api.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
%w{response filter post stream subscription token user}.each do |f|
|
3
|
+
%w{response filter post stream subscription token user message}.each do |f|
|
4
4
|
require_relative "api/#{f}"
|
5
5
|
end
|
6
6
|
|
@@ -14,7 +14,7 @@ module ADN
|
|
14
14
|
response = JSON.parse ADN::HTTP.request(request).body
|
15
15
|
|
16
16
|
Response.new(response).tap { |r|
|
17
|
-
raise ADN::API::Error, r
|
17
|
+
raise ADN::API::Error, r.error_message if r.has_error?
|
18
18
|
}
|
19
19
|
end
|
20
20
|
|
@@ -36,13 +36,15 @@ module ADN
|
|
36
36
|
|
37
37
|
def post(url, params = nil)
|
38
38
|
request = construct_request(:post, url)
|
39
|
-
request.
|
39
|
+
request.add_field('Content-Type', 'application/json')
|
40
|
+
request.body = params.to_json if params
|
40
41
|
perform(request)
|
41
42
|
end
|
42
43
|
|
43
44
|
def put(url, params = nil)
|
44
45
|
request = construct_request(:put, url)
|
45
|
-
request.
|
46
|
+
request.add_field('Content-Type', 'application/json')
|
47
|
+
request.body = params.to_json if params
|
46
48
|
perform(request)
|
47
49
|
end
|
48
50
|
|
data/lib/adn/constants.rb
CHANGED
@@ -8,7 +8,10 @@ module ADN
|
|
8
8
|
API_ENDPOINT_POSTS = "#{API_ENDPOINT}/posts"
|
9
9
|
API_ENDPOINT_USERS = "#{API_ENDPOINT}/users"
|
10
10
|
API_ENDPOINT_TOKEN = "#{API_ENDPOINT}/token"
|
11
|
+
API_ENDPOINT_CHANNELS = "#{API_ENDPOINT}/channels"
|
11
12
|
HTTP = Net::HTTP.new(API_HOST, 443)
|
12
13
|
|
14
|
+
HTTP_ERROR = 400
|
15
|
+
|
13
16
|
HTTP.use_ssl = true
|
14
17
|
end
|
data/lib/adn/message.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module ADN
|
4
|
+
class Message
|
5
|
+
attr_accessor(
|
6
|
+
:id, :message_id, :channel_id, :text,
|
7
|
+
:html, :source, :machine_only,
|
8
|
+
:reply_to, :thread_id,
|
9
|
+
:num_replies, :annotations, :entities,
|
10
|
+
)
|
11
|
+
|
12
|
+
attr_writer :user, :created_at
|
13
|
+
|
14
|
+
def self.send_message(params)
|
15
|
+
channel_id = params.delete('channel_id')
|
16
|
+
result = ADN::API::Message.create(channel_id, params)
|
17
|
+
Message.new(result["data"])
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.by_id(channel_id, id)
|
21
|
+
result = ADN::API::Message.by_id(channel_id, id)
|
22
|
+
Message.new(result["data"])
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(raw_message)
|
26
|
+
set_values(raw_message)
|
27
|
+
message_id = id
|
28
|
+
|
29
|
+
if raw_message.length == 2 and raw_message.key? :id and raw_message.key? :channel_id
|
30
|
+
# If we only have the bare minimum data, assume we want to get values from the server
|
31
|
+
message_details = details
|
32
|
+
if message_details.has_key? "data"
|
33
|
+
set_values(message_details["data"])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def details
|
39
|
+
# if we have a source, then we've loaded stuff from the server
|
40
|
+
if source
|
41
|
+
value = self.instance_variables.map do |i|
|
42
|
+
[i.to_s.slice(1..-1), self.instance_variable_get(i)]
|
43
|
+
end
|
44
|
+
Hash[value]
|
45
|
+
else
|
46
|
+
ADN::API::Message.by_id(channel_id, message_id)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def created_at
|
51
|
+
DateTime.parse(@created_at)
|
52
|
+
end
|
53
|
+
|
54
|
+
def user
|
55
|
+
ADN::User.new(@user)
|
56
|
+
end
|
57
|
+
|
58
|
+
def delete
|
59
|
+
result = ADN::API::Message.delete(channel_id, id)
|
60
|
+
ADN.create_instance(result["data"], Message)
|
61
|
+
end
|
62
|
+
|
63
|
+
def set_values(values)
|
64
|
+
values.each_pair { |k, v| send("#{k}=", v) if respond_to?("#{k}=") }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/adn/post.rb
CHANGED
@@ -9,7 +9,7 @@ module ADN
|
|
9
9
|
:annotations, :entities, :you_reposted,
|
10
10
|
:you_starred, :reposters, :starred_by
|
11
11
|
)
|
12
|
-
|
12
|
+
|
13
13
|
attr_writer :user, :created_at
|
14
14
|
|
15
15
|
def self.send_post(params)
|
@@ -17,6 +17,11 @@ module ADN
|
|
17
17
|
Post.new(result["data"])
|
18
18
|
end
|
19
19
|
|
20
|
+
def self.by_id(id)
|
21
|
+
result = ADN::API::Post.by_id(id)
|
22
|
+
Post.new(result["data"])
|
23
|
+
end
|
24
|
+
|
20
25
|
def initialize(raw_post)
|
21
26
|
if raw_post.respond_to?(:each_pair)
|
22
27
|
set_values(raw_post)
|
data/lib/adn/recipes.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module ADN
|
4
|
+
module Recipes
|
5
|
+
def self.send_broadcast(params)
|
6
|
+
channel_id = params.delete('channel_id')
|
7
|
+
broadcast = params.delete('broadcast')
|
8
|
+
text = params.delete('text')
|
9
|
+
read_more_link = params.delete('read_more_link')
|
10
|
+
|
11
|
+
message = {
|
12
|
+
annotations: [
|
13
|
+
{
|
14
|
+
type: 'net.app.core.broadcast.message.metadata',
|
15
|
+
value: {
|
16
|
+
subject: broadcast
|
17
|
+
}
|
18
|
+
}
|
19
|
+
],
|
20
|
+
text: text,
|
21
|
+
machine_only: (not text)
|
22
|
+
}
|
23
|
+
|
24
|
+
if read_more_link
|
25
|
+
message[:annotations] << {
|
26
|
+
type: 'net.app.core.crosspost',
|
27
|
+
value: {
|
28
|
+
canonical_url: read_more_link
|
29
|
+
}
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
result = ADN::API::Message.create(channel_id, message)
|
34
|
+
Message.new(result["data"])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/adn/user.rb
CHANGED
data/lib/adn/version.rb
CHANGED
data/lib/adn.rb
CHANGED
@@ -27,7 +27,9 @@ require 'uri'
|
|
27
27
|
require 'json'
|
28
28
|
require 'date'
|
29
29
|
|
30
|
-
%w{constants api post user version}.each
|
30
|
+
%w{constants api message post user version recipes}.each do |f|
|
31
|
+
require_relative "adn/#{f}"
|
32
|
+
end
|
31
33
|
|
32
34
|
module ADN
|
33
35
|
Error = Class.new StandardError
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require_relative '../../spec_helper'
|
4
|
+
|
5
|
+
describe ADN::API::Message do
|
6
|
+
subject { ADN::API::Message }
|
7
|
+
|
8
|
+
let(:base_path) { '/stream/0/channels' }
|
9
|
+
let(:error_message) {
|
10
|
+
'Call requires authentication: This view requires authentication and no token was provided.'
|
11
|
+
}
|
12
|
+
|
13
|
+
let(:error_response) {
|
14
|
+
OpenStruct.new(:body => %Q{ { "meta" : {
|
15
|
+
"code" : 401,
|
16
|
+
"error_id" : "6f5137beac6c4b9ea8dbec8e50aa9f38$32a85f1c22e98de98ea2ddabaf76c5ae",
|
17
|
+
"error_message" : "#{error_message}"
|
18
|
+
}} })
|
19
|
+
}
|
20
|
+
|
21
|
+
describe "new" do
|
22
|
+
it "messages the passed in params to the API" do
|
23
|
+
args(:post) {
|
24
|
+
path, params = subject.create(1, { foo: 'bar' })
|
25
|
+
|
26
|
+
path.must_equal base_path + '/1/messages'
|
27
|
+
params.must_equal foo: 'bar'
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'retrieves error message correctly' do
|
32
|
+
ADN::HTTP.stub(:request, error_response) do
|
33
|
+
error_call = lambda {subject.create(1, { foo: 'bar' })}
|
34
|
+
error_call.must_raise ADN::API::Error
|
35
|
+
|
36
|
+
error = error_call.call rescue $!
|
37
|
+
error.message.must_equal error_message
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "retrieve" do
|
43
|
+
it "retrieves the message" do
|
44
|
+
arg(:get) { subject.retrieve(8, 22).must_equal base_path + "/8/messages/22" }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "by_id" do
|
49
|
+
it "is just an alias for retrieve" do
|
50
|
+
subject.stub(:retrieve, 'bar') do
|
51
|
+
subject.by_id(4, 456).must_equal 'bar'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "delete" do
|
57
|
+
it "deletes the message" do
|
58
|
+
arg(:delete) { subject.delete(5, 77).must_equal base_path + "/5/messages/77" }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/spec/adn/api/post_spec.rb
CHANGED
@@ -6,6 +6,12 @@ describe ADN::API::Post do
|
|
6
6
|
subject { ADN::API::Post }
|
7
7
|
|
8
8
|
let(:base_path) { '/stream/0/posts' }
|
9
|
+
let(:error_message) {'Call requires authentication: This view requires authentication and no token was provided.'}
|
10
|
+
let(:error_response) { OpenStruct.new(:body => %Q{ { "meta" : {
|
11
|
+
"code" : 401,
|
12
|
+
"error_id" : "6f5137beac6c4b9ea8dbec8e50aa9f38$32a85f1c22e98de98ea2ddabaf76c5ae",
|
13
|
+
"error_message" : "#{error_message}"
|
14
|
+
}} }) }
|
9
15
|
|
10
16
|
describe "new" do
|
11
17
|
it "posts the passed in params to the API" do
|
@@ -16,6 +22,17 @@ describe ADN::API::Post do
|
|
16
22
|
params.must_equal foo: 'bar'
|
17
23
|
}
|
18
24
|
end
|
25
|
+
|
26
|
+
it 'retrieves error message correctly' do
|
27
|
+
ADN::HTTP.stub(:request, error_response) do
|
28
|
+
error_call = lambda {subject.create({ foo: 'bar' })}
|
29
|
+
error_call.must_raise ADN::API::Error
|
30
|
+
|
31
|
+
error = error_call.call rescue $!
|
32
|
+
error.message.must_equal error_message
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
19
36
|
end
|
20
37
|
|
21
38
|
describe "retrieve" do
|
@@ -7,7 +7,7 @@ describe ADN::API::Response do
|
|
7
7
|
subject { ADN::API::Response }
|
8
8
|
|
9
9
|
it "currently checks a hash-like response for errors" do
|
10
|
-
subject.new("
|
11
|
-
subject.new("
|
10
|
+
subject.new("meta" => {"code" => 400}).has_error?.must_equal true
|
11
|
+
subject.new("meta" => {"code" => 200}).has_error?.must_equal false
|
12
12
|
end
|
13
13
|
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require_relative '../spec_helper'
|
4
|
+
|
5
|
+
def d(data)
|
6
|
+
{ 'data' => data }
|
7
|
+
end
|
8
|
+
|
9
|
+
describe ADN::Message do
|
10
|
+
subject { ADN::Message }
|
11
|
+
|
12
|
+
let(:empty_message) { subject.new({}) }
|
13
|
+
let(:message_with_id) { subject.new({ channel_id: '456', message_id: '123' }) }
|
14
|
+
let(:msg) { subject.new(message_data) }
|
15
|
+
|
16
|
+
let(:example_user) { { username: 'peterhellberg' } }
|
17
|
+
let(:message_data) {
|
18
|
+
{
|
19
|
+
created_at: '1999-12-31T23:59:59Z',
|
20
|
+
entities: {},
|
21
|
+
html: '<b>The sky above the port…</b>',
|
22
|
+
id: 10001,
|
23
|
+
channel_id: 65432,
|
24
|
+
num_replies: 1,
|
25
|
+
reply_to: 66,
|
26
|
+
source: { link: "https://alpha.app.net", name: "Alpha" },
|
27
|
+
text: "The sky above the port…",
|
28
|
+
thread_id: "301856",
|
29
|
+
user: example_user
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
describe "send_message" do
|
34
|
+
it "creates a message via the API" do
|
35
|
+
ADN::API::Message.stub(:create, ADN::API::Response.new(d(message_data))) do
|
36
|
+
m = subject.send_message({})
|
37
|
+
m.text.must_equal 'The sky above the port…'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "initialize" do
|
43
|
+
it "populates the accessors using the passed in hash" do
|
44
|
+
m = subject.new text: 'foo', id: 123, channel_id: 456
|
45
|
+
m.text.must_equal 'foo'
|
46
|
+
end
|
47
|
+
|
48
|
+
# TODO: Change this behavior (Add a find method instead)
|
49
|
+
it "populates the accessors based on the passed in id" do
|
50
|
+
ADN::API::Message.stub(:by_id, ->(c_id, i){ d({ "text" => 'bar'}) }) do
|
51
|
+
m = subject.new id: 123, channel_id: 456
|
52
|
+
m.text.must_equal 'bar'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "details" do
|
58
|
+
it "returns the details for the message" do
|
59
|
+
msg.details.keys.must_equal [
|
60
|
+
"created_at", "entities", "html",
|
61
|
+
"id", "channel_id", "num_replies", "reply_to",
|
62
|
+
"source", "text", "thread_id", "user"
|
63
|
+
]
|
64
|
+
end
|
65
|
+
|
66
|
+
it "returns the message from the api if it has no id" do
|
67
|
+
|
68
|
+
ADN::API::Message.stub(:by_id, ->(c_id, i){ d({ "id" => i, "channel_id" => c_id}) }) do
|
69
|
+
message_with_id.details.
|
70
|
+
must_equal({ "data" => { "id" => '123', "channel_id" => '456' } })
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "created_at" do
|
76
|
+
it "returns the date and time the message was created" do
|
77
|
+
msg.created_at.to_s.must_equal '1999-12-31T23:59:59+00:00'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "user" do
|
82
|
+
it "returns the user" do
|
83
|
+
msg.user.username.must_equal 'peterhellberg'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "delete" do
|
88
|
+
it "deletes the message via the API and returns the message" do
|
89
|
+
delete_stub = ->(c_id, id){
|
90
|
+
ADN::API::Response.new("data" => { "channel_id" => c_id, "id" => id })
|
91
|
+
}
|
92
|
+
|
93
|
+
ADN::API::Message.stub(:delete, delete_stub) do
|
94
|
+
msg.delete.id.must_equal 10001
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "set_values" do
|
100
|
+
it "sets values with accessors" do
|
101
|
+
m = empty_message
|
102
|
+
|
103
|
+
m.set_values(message_data)
|
104
|
+
|
105
|
+
m.entities.must_equal message_data[:entities]
|
106
|
+
m.html.must_equal message_data[:html]
|
107
|
+
m.id.must_equal message_data[:id]
|
108
|
+
m.num_replies.must_equal message_data[:num_replies]
|
109
|
+
m.reply_to.must_equal message_data[:reply_to]
|
110
|
+
m.source.must_equal message_data[:source]
|
111
|
+
m.text.must_equal message_data[:text]
|
112
|
+
m.thread_id.must_equal message_data[:thread_id]
|
113
|
+
|
114
|
+
m.created_at.must_equal DateTime.parse(message_data[:created_at])
|
115
|
+
|
116
|
+
m.user.username.must_equal message_data[:user][:username]
|
117
|
+
end
|
118
|
+
|
119
|
+
it "does not set arbitrary values" do
|
120
|
+
m = subject.new foo: 'bar'
|
121
|
+
-> { m.foo }.must_raise NoMethodError
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
data/spec/adn_spec.rb
CHANGED
@@ -19,9 +19,10 @@ describe ADN do
|
|
19
19
|
ADN::API_HOST.must_equal 'alpha-api.app.net'
|
20
20
|
end
|
21
21
|
|
22
|
-
it "has constants containing the API endpoints for posts and
|
22
|
+
it "has constants containing the API endpoints for posts, users, and channels" do
|
23
23
|
ADN::API_ENDPOINT_POSTS.must_equal '/stream/0/posts'
|
24
24
|
ADN::API_ENDPOINT_USERS.must_equal '/stream/0/users'
|
25
|
+
ADN::API_ENDPOINT_CHANNELS.must_equal '/stream/0/channels'
|
25
26
|
end
|
26
27
|
|
27
28
|
it "has constants containing the API endpoints for tokens" do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.6
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Kishyr Ramdial
|
@@ -11,7 +10,7 @@ authors:
|
|
11
10
|
autorequire:
|
12
11
|
bindir: bin
|
13
12
|
cert_chain: []
|
14
|
-
date:
|
13
|
+
date: 2013-12-11 00:00:00.000000000 Z
|
15
14
|
dependencies: []
|
16
15
|
description: A simple and easy to use library to interact with App.net's API
|
17
16
|
email:
|
@@ -33,6 +32,7 @@ files:
|
|
33
32
|
- lib/adn.rb
|
34
33
|
- lib/adn/api.rb
|
35
34
|
- lib/adn/api/filter.rb
|
35
|
+
- lib/adn/api/message.rb
|
36
36
|
- lib/adn/api/post.rb
|
37
37
|
- lib/adn/api/response.rb
|
38
38
|
- lib/adn/api/stream.rb
|
@@ -40,57 +40,59 @@ files:
|
|
40
40
|
- lib/adn/api/token.rb
|
41
41
|
- lib/adn/api/user.rb
|
42
42
|
- lib/adn/constants.rb
|
43
|
+
- lib/adn/message.rb
|
43
44
|
- lib/adn/post.rb
|
45
|
+
- lib/adn/recipes.rb
|
44
46
|
- lib/adn/user.rb
|
45
47
|
- lib/adn/version.rb
|
46
48
|
- spec/adn/api/filter_spec.rb
|
49
|
+
- spec/adn/api/message_spec.rb
|
47
50
|
- spec/adn/api/post_spec.rb
|
48
51
|
- spec/adn/api/response_spec.rb
|
49
52
|
- spec/adn/api/stream_spec.rb
|
50
53
|
- spec/adn/api/subscription_spec.rb
|
51
54
|
- spec/adn/api/token_spec.rb
|
52
55
|
- spec/adn/api/user_spec.rb
|
56
|
+
- spec/adn/message_spec.rb
|
53
57
|
- spec/adn/post_spec.rb
|
54
58
|
- spec/adn/user_spec.rb
|
55
59
|
- spec/adn_spec.rb
|
56
60
|
- spec/fixtures/post.json
|
57
61
|
- spec/fixtures/user.json
|
58
62
|
- spec/spec_helper.rb
|
59
|
-
homepage: https://github.com/
|
63
|
+
homepage: https://github.com/adn-rb/adn
|
60
64
|
licenses: []
|
65
|
+
metadata: {}
|
61
66
|
post_install_message:
|
62
67
|
rdoc_options: []
|
63
68
|
require_paths:
|
64
69
|
- lib
|
65
70
|
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
71
|
requirements:
|
68
|
-
- -
|
72
|
+
- - '>='
|
69
73
|
- !ruby/object:Gem::Version
|
70
74
|
version: 1.9.3
|
71
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
-
none: false
|
73
76
|
requirements:
|
74
|
-
- -
|
77
|
+
- - '>='
|
75
78
|
- !ruby/object:Gem::Version
|
76
79
|
version: '0'
|
77
|
-
segments:
|
78
|
-
- 0
|
79
|
-
hash: 2181708405046728371
|
80
80
|
requirements: []
|
81
81
|
rubyforge_project:
|
82
|
-
rubygems_version: 1.
|
82
|
+
rubygems_version: 2.1.3
|
83
83
|
signing_key:
|
84
|
-
specification_version:
|
84
|
+
specification_version: 4
|
85
85
|
summary: A Ruby library for App.net
|
86
86
|
test_files:
|
87
87
|
- spec/adn/api/filter_spec.rb
|
88
|
+
- spec/adn/api/message_spec.rb
|
88
89
|
- spec/adn/api/post_spec.rb
|
89
90
|
- spec/adn/api/response_spec.rb
|
90
91
|
- spec/adn/api/stream_spec.rb
|
91
92
|
- spec/adn/api/subscription_spec.rb
|
92
93
|
- spec/adn/api/token_spec.rb
|
93
94
|
- spec/adn/api/user_spec.rb
|
95
|
+
- spec/adn/message_spec.rb
|
94
96
|
- spec/adn/post_spec.rb
|
95
97
|
- spec/adn/user_spec.rb
|
96
98
|
- spec/adn_spec.rb
|