sheep 0.0.1a → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,30 @@
1
+ module Sheep
2
+ class Activity
3
+ def initialize(data)
4
+ @data = {}
5
+ data.each do |key, value|
6
+ self[key] = value
7
+ end
8
+ end
9
+
10
+ def method_missing(attribute, value = nil)
11
+ if attribute =~/\=$/
12
+ self[attribute.to_s.gsub(/\=$/, '')] = value
13
+ else
14
+ self[attribute]
15
+ end
16
+ end
17
+
18
+ def [](attribute)
19
+ @data[attribute.to_s]
20
+ end
21
+
22
+ def []=(attribute, value)
23
+ @data[attribute.to_s] = value
24
+ end
25
+
26
+ def ==(other)
27
+ self.data == other.data
28
+ end
29
+ end
30
+ end
data/lib/sheep/user.rb CHANGED
@@ -24,12 +24,25 @@ module Sheep
24
24
  request.params['client_secret'] = Sheep.client_secret
25
25
  request.params['grant_type'] = 'password'
26
26
  end
27
+ # TODO: access_token should be in user object, not global
27
28
  Sheep.access_token = response.body['access_token']
28
29
  end
29
30
  end
30
31
 
32
+ def activities
33
+ response = Sheep.connection.get('/v1/activities') do |request|
34
+ request.headers['Authorization'] = "Bearer #{Sheep.access_token}"
35
+ end
36
+ response.body.map do |activity|
37
+ Sheep::Activity.new(activity['activity'])
38
+ end
39
+ end
40
+
31
41
  def initialize(data)
32
- @data = data
42
+ @data = {}
43
+ data.each do |key, value|
44
+ self[key] = value
45
+ end
33
46
  end
34
47
 
35
48
  def method_missing(attribute, value = nil)
data/lib/sheep/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sheep
2
- VERSION = "0.0.1a"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/sheep.rb CHANGED
@@ -5,6 +5,7 @@ lib_dir = File.expand_path('../', __FILE__)
5
5
  $: << lib_dir unless $:.include?(lib_dir)
6
6
 
7
7
  require 'sheep/user'
8
+ require 'sheep/activity'
8
9
  require 'sheep/error'
9
10
 
10
11
  module Sheep
data/spec/app_helper.rb CHANGED
@@ -12,4 +12,8 @@ class App < Sinatra::Base
12
12
  post '/v1/oauth/access_token' do
13
13
  [200, {}, %|{"access_token":"access_token"}|]
14
14
  end
15
+
16
+ get '/v1/activities' do
17
+ %|[{"activity":{"id":1,"title":"Hello World","text":"Very funny story"}}]|
18
+ end
15
19
  end
@@ -0,0 +1,8 @@
1
+ describe Sheep::Activity do
2
+ it 'initializes attributes' do
3
+ activity = Sheep::Activity.new(:id => 1, :title => 'title', :text => 'text')
4
+ activity.id.should == 1
5
+ activity.title.should == 'title'
6
+ activity.text.should == 'text'
7
+ end
8
+ end
@@ -58,4 +58,14 @@ describe Sheep::User do
58
58
  Sheep.access_token.should == 'access_token'
59
59
  end
60
60
  end
61
+
62
+ context 'activities' do
63
+ before do
64
+ @user = Sheep::User.find('krekoten')
65
+ end
66
+
67
+ it 'returns array of activities' do
68
+ @user.activities.should == [Sheep::Activity.new(:id => 1, :title => 'Hello World', :text => 'Very funny story')]
69
+ end
70
+ end
61
71
  end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sheep
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: 5
5
- version: 0.0.1a
4
+ prerelease:
5
+ version: 0.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - "Marjan Krekoten' (\xD0\x9C\xD0\xB0\xD1\x80'\xD1\x8F\xD0\xBD \xD0\x9A\xD1\x80\xD0\xB5\xD0\xBA\xD0\xBE\xD1\x82\xD0\xB5\xD0\xBD\xD1\x8C)"
@@ -10,8 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-29 00:00:00 +03:00
14
- default_executable:
13
+ date: 2011-04-12 00:00:00 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: rspec
@@ -94,17 +93,18 @@ files:
94
93
  - README.md
95
94
  - Rakefile
96
95
  - lib/sheep.rb
96
+ - lib/sheep/activity.rb
97
97
  - lib/sheep/error.rb
98
98
  - lib/sheep/user.rb
99
99
  - lib/sheep/version.rb
100
100
  - sheep.gemspec
101
101
  - spec/app_helper.rb
102
102
  - spec/quality_spec.rb
103
+ - spec/sheep/activity_spec.rb
103
104
  - spec/sheep/error_spec.rb
104
105
  - spec/sheep/user_spec.rb
105
106
  - spec/sheep_spec.rb
106
107
  - spec/spec_helper.rb
107
- has_rdoc: true
108
108
  homepage: ""
109
109
  licenses: []
110
110
 
@@ -122,19 +122,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
122
  required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  none: false
124
124
  requirements:
125
- - - ">"
125
+ - - ">="
126
126
  - !ruby/object:Gem::Version
127
- version: 1.3.1
127
+ version: "0"
128
128
  requirements: []
129
129
 
130
130
  rubyforge_project: "[none]"
131
- rubygems_version: 1.6.2
131
+ rubygems_version: 1.7.2
132
132
  signing_key:
133
133
  specification_version: 3
134
134
  summary: Funny sheep Tuppy
135
135
  test_files:
136
136
  - spec/app_helper.rb
137
137
  - spec/quality_spec.rb
138
+ - spec/sheep/activity_spec.rb
138
139
  - spec/sheep/error_spec.rb
139
140
  - spec/sheep/user_spec.rb
140
141
  - spec/sheep_spec.rb