adn 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +15 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +3 -3
- data/README.md +0 -16
- data/lib/adn.rb +4 -8
- data/lib/adn/api.rb +15 -5
- data/lib/adn/api/post.rb +5 -1
- data/lib/adn/api/user.rb +0 -4
- data/lib/adn/post.rb +13 -4
- data/lib/adn/user.rb +33 -43
- data/lib/adn/version.rb +1 -1
- data/spec/adn/api/post_spec.rb +11 -0
- data/spec/adn/api/token_spec.rb +4 -2
- data/spec/adn/api/user_spec.rb +0 -8
- data/spec/adn/post_spec.rb +2 -1
- data/spec/adn/user_spec.rb +17 -30
- data/spec/adn_spec.rb +1 -1
- metadata +4 -3
data/CHANGELOG.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
### Changelog
|
2
|
+
|
3
|
+
* **Version 0.3.5** (23 October 2012)
|
4
|
+
* Added the unified stream
|
5
|
+
* **Version 0.3.1** (28 August 2012)
|
6
|
+
* Fixed naming conflict.
|
7
|
+
* **Version 0.3** (28 August 2012)
|
8
|
+
* Now includes a Post class that describes each post along with a bunch of new methods of accessing a post's replies and the post's original post.
|
9
|
+
* Users methods that return user details (follow, unfollow, following, followers, mute, unmute, mute_list) will now return either a User object back, or an array of User objects.
|
10
|
+
* Similarly, User methods that return post details (posts, mentions, stream) will return a Post object, or an array of Post objects.
|
11
|
+
* To accomplish all this, I've had to change the module structure which will break existing code if you've relied on the modules to access any data. Basically, all modules begin with ADN::API:: now (eg. ADN::API::Post, ADN::API::User).
|
12
|
+
* **Version 0.2** (27 August 2012)
|
13
|
+
* Changed all existing classes to modules and introduced the User class for easily accessing user details.
|
14
|
+
* **Version 0.1** (26 August 2012)
|
15
|
+
* Really basic functionality for all existing App.new API methods as per the spec.
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
adn (0.3.
|
4
|
+
adn (0.3.5)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
|
-
minitest (
|
9
|
+
minitest (4.1.0)
|
10
10
|
rake (0.9.2.2)
|
11
11
|
|
12
12
|
PLATFORMS
|
@@ -14,5 +14,5 @@ PLATFORMS
|
|
14
14
|
|
15
15
|
DEPENDENCIES
|
16
16
|
adn!
|
17
|
-
minitest (~>
|
17
|
+
minitest (~> 4.1)
|
18
18
|
rake
|
data/README.md
CHANGED
@@ -39,22 +39,6 @@ For API calls that accept parameters described in the App.net API Spec, simply p
|
|
39
39
|
|
40
40
|
Complete documentation will be available soon, but in the meantime you can browse all API methods in `lib/adnruby.rb`.
|
41
41
|
|
42
|
-
### Changelog
|
43
|
-
|
44
|
-
* **Version 0.3.1** (28 August 2012)
|
45
|
-
* Fixed naming conflict
|
46
|
-
* **Version 0.3** (28 August 2012)
|
47
|
-
* Now includes a Post class that describes each post along with a bunch of new methods of accessing a post's replies and the post's original post.
|
48
|
-
* Users methods that return user details (follow, unfollow, following, followers, mute, unmute, mute_list) will now return either a User object back, or an array of User objects.
|
49
|
-
* Similarly, User methods that return post details (posts, mentions, stream) will return a Post object, or an array of Post objects.
|
50
|
-
* To accomplish all this, I've had to change the module structure which will break existing code if you've relied on the modules to access any data. Basically, all modules begin with ADN::API:: now (eg. ADN::API::Post, ADN::API::User).
|
51
|
-
* **Version 0.2** (27 August 2012)
|
52
|
-
* Changed all existing classes to modules and introduced the User class for easily accessing user details
|
53
|
-
* **Version 0.1** (26 August 2012)
|
54
|
-
* Really basic functionality for all existing App.new API methods as per the spec.
|
55
|
-
|
56
|
-
---
|
57
|
-
|
58
42
|
### License
|
59
43
|
|
60
44
|
**ADN** is licensed under the MIT License and is Copyright (c) 2012 Kishyr Ramdial.
|
data/lib/adn.rb
CHANGED
@@ -30,14 +30,10 @@ require 'date'
|
|
30
30
|
%w{constants api post user version}.each { |f| require_relative "adn/#{f}" }
|
31
31
|
|
32
32
|
module ADN
|
33
|
-
|
33
|
+
Error = Class.new StandardError
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
def self.token
|
40
|
-
@token
|
35
|
+
class << self
|
36
|
+
attr_accessor :token
|
41
37
|
end
|
42
38
|
|
43
39
|
def self.create_instance(data, type)
|
@@ -45,6 +41,6 @@ module ADN
|
|
45
41
|
end
|
46
42
|
|
47
43
|
def self.create_collection(data, type)
|
48
|
-
data.
|
44
|
+
data.map { |t| type.new(t) }
|
49
45
|
end
|
50
46
|
end
|
data/lib/adn/api.rb
CHANGED
@@ -6,7 +6,7 @@ end
|
|
6
6
|
|
7
7
|
module ADN
|
8
8
|
module API
|
9
|
-
|
9
|
+
Error = Class.new StandardError
|
10
10
|
|
11
11
|
class << self
|
12
12
|
def perform(request)
|
@@ -18,26 +18,36 @@ module ADN
|
|
18
18
|
}
|
19
19
|
end
|
20
20
|
|
21
|
+
def construct_request(verb, url)
|
22
|
+
http_method = case verb
|
23
|
+
when :post then Net::HTTP::Post
|
24
|
+
when :put then Net::HTTP::Put
|
25
|
+
when :delete then Net::HTTP::Delete
|
26
|
+
else Net::HTTP::Get
|
27
|
+
end
|
28
|
+
http_method.new(url)
|
29
|
+
end
|
30
|
+
|
21
31
|
def get(url, params = nil)
|
22
32
|
url = params.nil? ? url : [url, URI.encode_www_form(params)].join("?")
|
23
|
-
request =
|
33
|
+
request = construct_request(:get, url)
|
24
34
|
perform(request)
|
25
35
|
end
|
26
36
|
|
27
37
|
def post(url, params = nil)
|
28
|
-
request =
|
38
|
+
request = construct_request(:post, url)
|
29
39
|
request.set_form_data(params) if params
|
30
40
|
perform(request)
|
31
41
|
end
|
32
42
|
|
33
43
|
def put(url, params = nil)
|
34
|
-
request =
|
44
|
+
request = construct_request(:put, url)
|
35
45
|
request.set_form_data(params) if params
|
36
46
|
perform(request)
|
37
47
|
end
|
38
48
|
|
39
49
|
def delete(url)
|
40
|
-
request =
|
50
|
+
request = construct_request(:delete, url)
|
41
51
|
perform(request)
|
42
52
|
end
|
43
53
|
end
|
data/lib/adn/api/post.rb
CHANGED
@@ -39,9 +39,13 @@ module ADN
|
|
39
39
|
ADN::API.get("#{ADN::API_ENDPOINT_POSTS}/stream/global", params)
|
40
40
|
end
|
41
41
|
|
42
|
+
def self.unified_stream(params = nil)
|
43
|
+
ADN::API.get("#{ADN::API_ENDPOINT_POSTS}/stream/unified", params)
|
44
|
+
end
|
45
|
+
|
42
46
|
def self.by_hashtag(hashtag, params = nil)
|
43
47
|
ADN::API.get("#{ADN::API_ENDPOINT_POSTS}/tag/#{hashtag}", params)
|
44
48
|
end
|
45
49
|
end
|
46
50
|
end
|
47
|
-
end
|
51
|
+
end
|
data/lib/adn/api/user.rb
CHANGED
data/lib/adn/post.rb
CHANGED
@@ -2,9 +2,15 @@
|
|
2
2
|
|
3
3
|
module ADN
|
4
4
|
class Post
|
5
|
-
attr_accessor
|
6
|
-
|
7
|
-
|
5
|
+
attr_accessor(
|
6
|
+
:id, :post_id, :text, :html, :source, :machine_only,
|
7
|
+
:reply_to, :thread_id, :canonical_url,
|
8
|
+
:num_replies, :num_reposts, :num_stars,
|
9
|
+
:annotations, :entities, :you_reposted,
|
10
|
+
:you_starred, :reposters, :starred_by
|
11
|
+
)
|
12
|
+
|
13
|
+
attr_writer :user, :created_at
|
8
14
|
|
9
15
|
def self.send_post(params)
|
10
16
|
result = ADN::API::Post.create(params)
|
@@ -26,7 +32,10 @@ module ADN
|
|
26
32
|
|
27
33
|
def details
|
28
34
|
if id
|
29
|
-
|
35
|
+
value = self.instance_variables.map do |i|
|
36
|
+
[i.to_s.slice(1..-1), self.instance_variable_get(i)]
|
37
|
+
end
|
38
|
+
Hash[value]
|
30
39
|
else
|
31
40
|
ADN::API::Post.by_id(post_id)
|
32
41
|
end
|
data/lib/adn/user.rb
CHANGED
@@ -2,36 +2,25 @@
|
|
2
2
|
|
3
3
|
module ADN
|
4
4
|
class User
|
5
|
-
attr_accessor
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
attr_accessor(
|
6
|
+
:id, :user_id, :username, :name, :description,
|
7
|
+
:timezone, :locale, :avatar_image,
|
8
|
+
:cover_image, :type, :counts, :app_data,
|
9
|
+
:follows_you, :you_follow, :you_muted
|
10
|
+
)
|
11
|
+
|
12
|
+
attr_writer :created_at
|
11
13
|
|
12
14
|
def self.me
|
13
|
-
new ADN::API::Token.current[
|
15
|
+
new ADN::API::Token.current["user"]
|
14
16
|
end
|
15
17
|
|
16
|
-
def
|
17
|
-
|
18
|
-
set_values(user)
|
19
|
-
self.user_id = id.to_s
|
20
|
-
else
|
21
|
-
self.user_id = user.to_s
|
22
|
-
user_details = details
|
23
|
-
if details.has_key? "data"
|
24
|
-
set_values(user_details["data"])
|
25
|
-
end
|
26
|
-
end
|
18
|
+
def self.find(user_id)
|
19
|
+
new ADN::API::User.retrieve(user_id)
|
27
20
|
end
|
28
21
|
|
29
|
-
def
|
30
|
-
|
31
|
-
Hash[self.instance_variables.map { |i| [i.to_s.slice(1..-1), self.instance_variable_get(i)]}]
|
32
|
-
else
|
33
|
-
ADN::API::User.retrieve(user_id)
|
34
|
-
end
|
22
|
+
def initialize(user_data = {})
|
23
|
+
set_values(user_data)
|
35
24
|
end
|
36
25
|
|
37
26
|
def created_at
|
@@ -40,20 +29,16 @@ module ADN
|
|
40
29
|
|
41
30
|
# Followers/Users
|
42
31
|
|
43
|
-
def get_user(user)
|
44
|
-
user.is_a?(ADN::User) ? user.id : user
|
45
|
-
end
|
46
|
-
|
47
32
|
def follow(user)
|
48
|
-
|
49
|
-
result = ADN.post("/stream/0/users/#{user_id}/follow")
|
33
|
+
result = ADN.post("#{ADN::API_ENDPOINT_USERS}/#{user.user_id}/follow")
|
50
34
|
ADN.create_instance(result["data"], User)
|
51
35
|
end
|
52
36
|
|
53
37
|
def unfollow(user)
|
54
|
-
|
55
|
-
|
56
|
-
|
38
|
+
if user.valid_user?
|
39
|
+
result = ADN.delete("#{ADN::API_ENDPOINT_USERS}/#{user.user_id}/follow")
|
40
|
+
ADN.create_instance(result["data"], User)
|
41
|
+
end
|
57
42
|
end
|
58
43
|
|
59
44
|
def followers
|
@@ -69,15 +54,17 @@ module ADN
|
|
69
54
|
# Mute
|
70
55
|
|
71
56
|
def mute(user)
|
72
|
-
|
73
|
-
|
74
|
-
|
57
|
+
if user.valid_user?
|
58
|
+
result = ADN.post("#{ADN::API_ENDPOINT_USERS}/#{user.user_id}/mute")
|
59
|
+
ADN.create_instance(result["data"], User)
|
60
|
+
end
|
75
61
|
end
|
76
62
|
|
77
63
|
def unmute(user)
|
78
|
-
|
79
|
-
|
80
|
-
|
64
|
+
if user.valid_user?
|
65
|
+
result = ADN.delete("#{ADN::API_ENDPOINT_USERS}/#{user.user_id}/mute")
|
66
|
+
ADN.create_instance(result["data"], User)
|
67
|
+
end
|
81
68
|
end
|
82
69
|
|
83
70
|
def mute_list
|
@@ -102,12 +89,15 @@ module ADN
|
|
102
89
|
ADN.create_collection(result["data"], Post)
|
103
90
|
end
|
104
91
|
|
105
|
-
def
|
106
|
-
|
92
|
+
def valid_user?
|
93
|
+
!!user_id.match(/^\d+$/)
|
107
94
|
end
|
108
95
|
|
109
|
-
def
|
110
|
-
|
96
|
+
def set_values(values)
|
97
|
+
if values.respond_to? :each_pair
|
98
|
+
values.each_pair { |k, v| send("#{k}=", v) if respond_to?("#{k}=") }
|
99
|
+
self.user_id = id.to_s
|
100
|
+
end
|
111
101
|
end
|
112
102
|
end
|
113
103
|
end
|
data/lib/adn/version.rb
CHANGED
data/spec/adn/api/post_spec.rb
CHANGED
@@ -90,6 +90,17 @@ describe ADN::API::Post do
|
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
+
describe "unified_stream" do
|
94
|
+
it "retrieves the unified stream" do
|
95
|
+
args(:get) {
|
96
|
+
path, params = subject.unified_stream('baz')
|
97
|
+
|
98
|
+
path.must_equal base_path + "/stream/unified"
|
99
|
+
params.must_equal 'baz'
|
100
|
+
}
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
93
104
|
describe "by_hashtag" do
|
94
105
|
it "retrieves posts by hashtag" do
|
95
106
|
args(:get) {
|
data/spec/adn/api/token_spec.rb
CHANGED
@@ -7,13 +7,15 @@ describe ADN::API::Token do
|
|
7
7
|
|
8
8
|
describe "current" do
|
9
9
|
it "does not return the current token if it has an error" do
|
10
|
-
ADN::API.stub(
|
10
|
+
ADN::API.stub(
|
11
|
+
:get, ADN::API::Response.new("error" => "error message")) do
|
11
12
|
subject.current.must_equal nil
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
15
16
|
it "retrieves the current token" do
|
16
|
-
ADN::API.stub(
|
17
|
+
ADN::API.stub(
|
18
|
+
:get, ADN::API::Response.new("data" => "example_token")) do
|
17
19
|
subject.current.must_equal "example_token"
|
18
20
|
end
|
19
21
|
end
|
data/spec/adn/api/user_spec.rb
CHANGED
@@ -13,14 +13,6 @@ describe ADN::API::User do
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
describe "by_id" do
|
17
|
-
it "is just an alias for retrieve" do
|
18
|
-
subject.stub(:retrieve, 'foo') do
|
19
|
-
subject.by_id(123).must_equal 'foo'
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
16
|
describe "following" do
|
25
17
|
it "retrieves the following list" do
|
26
18
|
arg(:get) { subject.following(44).must_equal base_path + "44/following" }
|
data/spec/adn/post_spec.rb
CHANGED
@@ -95,7 +95,8 @@ describe ADN::Post do
|
|
95
95
|
|
96
96
|
describe "replies" do
|
97
97
|
it "returns a list of posts" do
|
98
|
-
response = ADN::API::Response.new(
|
98
|
+
response = ADN::API::Response.new(
|
99
|
+
"data" => [{ text: "foo"}, {text: "bar"}])
|
99
100
|
|
100
101
|
ADN::API::Post.stub(:replies, ->(*a){ response }) do
|
101
102
|
r = post.replies
|
data/spec/adn/user_spec.rb
CHANGED
@@ -5,9 +5,9 @@ require_relative '../spec_helper'
|
|
5
5
|
describe ADN::User do
|
6
6
|
subject { ADN::User }
|
7
7
|
|
8
|
-
let(:empty_user) { subject.new({})
|
9
|
-
let(:user)
|
10
|
-
let(:user_data)
|
8
|
+
let(:empty_user) { subject.new({}) }
|
9
|
+
let(:user) { subject.new(user_data) }
|
10
|
+
let(:user_data) { fixture('user.json') }
|
11
11
|
|
12
12
|
describe "me" do
|
13
13
|
it "retrieves the user based on the current token" do
|
@@ -19,24 +19,21 @@ describe ADN::User do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
describe "
|
23
|
-
it "
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
# TODO: Remove this behavior, wrong level of abstraction
|
29
|
-
it "populates the accessors based on the user id passed in" do
|
30
|
-
ADN::API::User.stub(:retrieve, { "data" => user_data }) do
|
31
|
-
u = subject.new(4821)
|
22
|
+
describe "find" do
|
23
|
+
it "retrieves the user data from the API and returns a User object" do
|
24
|
+
ADN::API::User.stub(:retrieve, user_data) do
|
25
|
+
u = subject.find("4821")
|
32
26
|
u.name.must_equal "Peter Hellberg"
|
33
27
|
u.user_id.must_equal "4821"
|
34
28
|
end
|
35
29
|
end
|
36
30
|
end
|
37
31
|
|
38
|
-
describe "
|
39
|
-
it "
|
32
|
+
describe "initialize" do
|
33
|
+
it "populates the accessors based on the raw user data passed in" do
|
34
|
+
u = subject.new(user_data)
|
35
|
+
u.name.must_equal "Peter Hellberg"
|
36
|
+
u.user_id.must_equal "4821"
|
40
37
|
end
|
41
38
|
end
|
42
39
|
|
@@ -46,16 +43,6 @@ describe ADN::User do
|
|
46
43
|
end
|
47
44
|
end
|
48
45
|
|
49
|
-
# TODO: Change the name to describe what
|
50
|
-
# it actually returns (user_id) or
|
51
|
-
# remove it completely
|
52
|
-
describe "get_user" do
|
53
|
-
it "returns a user id for some reason" do
|
54
|
-
empty_user.get_user(user).must_equal "4821"
|
55
|
-
empty_user.get_user(123).must_equal 123
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
46
|
describe "follow" do
|
60
47
|
it "" do
|
61
48
|
end
|
@@ -115,13 +102,13 @@ describe ADN::User do
|
|
115
102
|
end
|
116
103
|
end
|
117
104
|
|
118
|
-
describe "
|
119
|
-
it "returns
|
120
|
-
empty_user.
|
105
|
+
describe "valid_user?" do
|
106
|
+
it "returns false if no id" do
|
107
|
+
empty_user.valid_user?.must_equal false
|
121
108
|
end
|
122
109
|
|
123
|
-
it "returns
|
124
|
-
user.
|
110
|
+
it "returns true if the user has an id" do
|
111
|
+
user.valid_user?.must_equal true
|
125
112
|
end
|
126
113
|
end
|
127
114
|
end
|
data/spec/adn_spec.rb
CHANGED
@@ -23,7 +23,7 @@ describe ADN do
|
|
23
23
|
ADN::API_ENDPOINT_POSTS.must_equal '/stream/0/posts'
|
24
24
|
ADN::API_ENDPOINT_USERS.must_equal '/stream/0/users'
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
it "has constants containing the API endpoints for tokens" do
|
28
28
|
ADN::API_ENDPOINT_TOKEN.must_equal '/stream/0/token'
|
29
29
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-
|
14
|
+
date: 2012-10-23 00:00:00.000000000 Z
|
15
15
|
dependencies: []
|
16
16
|
description: A simple and easy to use library to interact with App.net's API
|
17
17
|
email:
|
@@ -24,6 +24,7 @@ extra_rdoc_files: []
|
|
24
24
|
files:
|
25
25
|
- .gitignore
|
26
26
|
- .travis.yml
|
27
|
+
- CHANGELOG.md
|
27
28
|
- Gemfile
|
28
29
|
- Gemfile.lock
|
29
30
|
- README.md
|
@@ -75,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
76
|
version: '0'
|
76
77
|
segments:
|
77
78
|
- 0
|
78
|
-
hash:
|
79
|
+
hash: 2181708405046728371
|
79
80
|
requirements: []
|
80
81
|
rubyforge_project:
|
81
82
|
rubygems_version: 1.8.24
|