adn 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- adn (0.3.3)
4
+ adn (0.3.4)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/lib/adn/api/token.rb CHANGED
@@ -5,7 +5,7 @@ module ADN
5
5
  module Token
6
6
  def self.current
7
7
  result = ADN::API.get(ADN::API_ENDPOINT_TOKEN)
8
- result["data"] unless result.has_error?
8
+ result["data"]
9
9
  end
10
10
  end
11
11
  end
data/lib/adn/post.rb CHANGED
@@ -8,7 +8,7 @@ module ADN
8
8
 
9
9
  def self.send_post(params)
10
10
  result = ADN::API::Post.create(params)
11
- Post.new(result["data"]) unless result.has_error?
11
+ Post.new(result["data"])
12
12
  end
13
13
 
14
14
  def initialize(raw_post)
@@ -42,17 +42,17 @@ module ADN
42
42
 
43
43
  def reply_to_post
44
44
  result = ADN::API::Post.by_id(reply_to)
45
- ADN.create_instance(result["data"], Post) unless result.has_error?
45
+ ADN.create_instance(result["data"], Post)
46
46
  end
47
47
 
48
48
  def replies(params = nil)
49
49
  result = ADN::API::Post.replies(id, params)
50
- ADN.create_collection(result["data"], Post) unless result.has_error?
50
+ ADN.create_collection(result["data"], Post)
51
51
  end
52
52
 
53
53
  def delete
54
54
  result = ADN::API::Post.delete(id)
55
- ADN.create_instance(result["data"], Post) unless result.has_error?
55
+ ADN.create_instance(result["data"], Post)
56
56
  end
57
57
 
58
58
  def set_values(values)
data/lib/adn/user.rb CHANGED
@@ -9,12 +9,16 @@ module ADN
9
9
  :locale, :name, :timezone, :type, :username,
10
10
  :you_follow, :you_muted
11
11
 
12
+ def self.me
13
+ new ADN::API::Token.current['user']
14
+ end
15
+
12
16
  def initialize(user)
13
17
  if user.respond_to?(:each_pair)
14
18
  set_values(user)
15
- self.user_id = id
19
+ self.user_id = id.to_s
16
20
  else
17
- self.user_id = user
21
+ self.user_id = user.to_s
18
22
  user_details = details
19
23
  if details.has_key? "data"
20
24
  set_values(user_details["data"])
@@ -43,23 +47,23 @@ module ADN
43
47
  def follow(user)
44
48
  user_id = get_user(user)
45
49
  result = ADN.post("/stream/0/users/#{user_id}/follow")
46
- ADN.create_instance(result["data"], User) unless result.has_error?
50
+ ADN.create_instance(result["data"], User)
47
51
  end
48
52
 
49
53
  def unfollow(user)
50
54
  user_id = get_user(user)
51
55
  result = ADN.delete("/stream/0/users/#{user_id}/follow")
52
- ADN.create_instance(result["data"], User) unless result.has_error?
56
+ ADN.create_instance(result["data"], User)
53
57
  end
54
58
 
55
59
  def followers
56
60
  result = ADN::API::User.followers(user_id)
57
- ADN.create_collection(result["data"], User) unless result.has_error?
61
+ ADN.create_collection(result["data"], User)
58
62
  end
59
63
 
60
64
  def following
61
65
  result = ADN::API::User.following(user_id)
62
- ADN.create_collection(result["data"], User) unless result.has_error?
66
+ ADN.create_collection(result["data"], User)
63
67
  end
64
68
 
65
69
  # Mute
@@ -67,35 +71,35 @@ module ADN
67
71
  def mute(user)
68
72
  user_id = get_user(user)
69
73
  result = ADN.post("#{ADN::API_ENDPOINT_USERS}/#{user_id}/mute")
70
- ADN.create_instance(result["data"], User) unless result.has_error?
74
+ ADN.create_instance(result["data"], User)
71
75
  end
72
76
 
73
77
  def unmute(user)
74
78
  user_id = get_user(user)
75
79
  result = ADN.delete("#{ADN::API_ENDPOINT_USERS}/#{user_id}/mute")
76
- ADN.create_instance(result["data"], User) unless result.has_error?
80
+ ADN.create_instance(result["data"], User)
77
81
  end
78
82
 
79
83
  def mute_list
80
84
  result = ADN.get("#{ADN::API_ENDPOINT_USERS}/me/muted")
81
- ADN.create_collection(result["data"], User) unless result.has_error?
85
+ ADN.create_collection(result["data"], User)
82
86
  end
83
87
 
84
88
  # Posts
85
89
 
86
90
  def posts(params = nil)
87
91
  result = ADN::API::Post.by_user(user_id, params)
88
- ADN.create_collection(result["data"], Post) unless result.has_error?
92
+ ADN.create_collection(result["data"], Post)
89
93
  end
90
94
 
91
95
  def stream(params = nil)
92
96
  result = ADN::API::Post.stream(params)
93
- ADN.create_collection(result["data"], Post) unless result.has_error?
97
+ ADN.create_collection(result["data"], Post)
94
98
  end
95
99
 
96
100
  def mentions(params = nil)
97
101
  result = ADN::API::Post.mentioning_user(user_id, params)
98
- ADN.create_collection(result["data"], Post) unless result.has_error?
102
+ ADN.create_collection(result["data"], Post)
99
103
  end
100
104
 
101
105
  def set_values(values)
data/lib/adn/version.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module ADN
4
4
  MAJOR = 0
5
5
  MINOR = 3
6
- TINY = 3
6
+ TINY = 4
7
7
  VERSION = [MAJOR, MINOR, TINY].join('.')
8
8
  end
9
9
 
data/lib/adn.rb CHANGED
@@ -40,10 +40,6 @@ module ADN
40
40
  @token
41
41
  end
42
42
 
43
- def self.has_error?(hash)
44
- hash.has_key?("error")
45
- end
46
-
47
43
  def self.create_instance(data, type)
48
44
  type.new(data)
49
45
  end
@@ -9,6 +9,16 @@ describe ADN::User do
9
9
  let(:user) { subject.new(user_data) }
10
10
  let(:user_data) { fixture('user.json') }
11
11
 
12
+ describe "me" do
13
+ it "retrieves the user based on the current token" do
14
+ ADN::API::Token.stub(:current, { "user" => user_data }) do
15
+ u = subject.me
16
+ u.user_id.must_equal "4821"
17
+ u.username.must_equal "peterhellberg"
18
+ end
19
+ end
20
+ end
21
+
12
22
  describe "initialize" do
13
23
  it "populates the accessors based on the raw user data passed in" do
14
24
  u = subject.new(user_data)
@@ -18,7 +28,7 @@ describe ADN::User do
18
28
  # TODO: Remove this behavior, wrong level of abstraction
19
29
  it "populates the accessors based on the user id passed in" do
20
30
  ADN::API::User.stub(:retrieve, { "data" => user_data }) do
21
- u = subject.new("4821")
31
+ u = subject.new(4821)
22
32
  u.name.must_equal "Peter Hellberg"
23
33
  u.user_id.must_equal "4821"
24
34
  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.3
4
+ version: 0.3.4
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-09-09 00:00:00.000000000 Z
14
+ date: 2012-09-10 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:
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  version: '0'
76
76
  segments:
77
77
  - 0
78
- hash: 817879158107129194
78
+ hash: -2288184448617261034
79
79
  requirements: []
80
80
  rubyforge_project:
81
81
  rubygems_version: 1.8.24