totter 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  .ruby-version
19
+ .DS_Store
data/lib/totter/client.rb CHANGED
@@ -5,6 +5,7 @@ module Totter
5
5
  class Client
6
6
  Dir[File.expand_path('../client/*.rb', __FILE__)].each { |f| require f }
7
7
 
8
+ include Activities
8
9
  include Avatars
9
10
  include Choices
10
11
  include Comments
@@ -21,24 +22,28 @@ module Totter
21
22
  attr_reader :api_host
22
23
  attr_reader :api_version
23
24
  attr_reader :transport
25
+ attr_reader :result_format
24
26
 
25
- @@stubbed = false
26
-
27
+ # Default parameters for the client
27
28
  DEFAULTS = {
28
29
  :api_scheme => 'https',
29
30
  :api_host => 'api.seesaw.co',
30
31
  :api_version => '1',
32
+ :result_format => :mashie,
31
33
  :transport => :http
32
34
  }
33
35
 
36
+ # The current configuration parameters for all clients
34
37
  def self.options
35
38
  @options ||= Hashie::Mash.new(DEFAULTS.dup)
36
39
  end
37
40
 
41
+ # Sets the current configuration parameters for all clients
38
42
  def self.options=(val)
39
43
  @options = val
40
44
  end
41
45
 
46
+ # Allows the setting of configuration parameters in a configure block.
42
47
  def self.configure
43
48
  yield options
44
49
  end
@@ -56,6 +61,7 @@ module Totter
56
61
  @api_version = options[:api_version]
57
62
  @client_token = options[:client_token] if options[:client_token]
58
63
  @transport = options[:transport]
64
+ @result_format = options[:result_format]
59
65
 
60
66
  # Include transport
61
67
  transport_module = Totter::Transport::TRANSPORT_MAP[@transport]
@@ -84,16 +90,6 @@ module Totter
84
90
  @api_scheme == 'https'
85
91
  end
86
92
 
87
- # Turns on stubbing. When called, all HTTP API calls will return an empty response
88
- def self.stub!
89
- @@stubbed = true
90
- end
91
-
92
- # Turns off stubing. Once called, HTTP requests will be sent as normal
93
- def self.unstub!
94
- @@stubbed = false
95
- end
96
-
97
93
  # Returns the current status of HTTP stubbing
98
94
  def self.stubbed?
99
95
  @@stubbed
@@ -0,0 +1,46 @@
1
+ module Totter
2
+ class Client
3
+ # Client methods for working with activities in the application.
4
+ module Activities
5
+ # Default query parameters for retrieving activities
6
+ DEFAULT_ACTIVITY_OPTIONS = {
7
+ :limit => 50,
8
+ :offset => 0
9
+ }
10
+
11
+ # Returns a user's activities
12
+ #
13
+ # @param user_id [Numeric] The user's id
14
+ # @param options [Hash] Parameters for returning selected activities
15
+ # @return [Hashie::Mash]
16
+ # @example
17
+ # Totter.activity(1)
18
+ def activities(user_id, options = DEFAULT_ACTIVITY_OPTIONS)
19
+ get("users/#{user_id}/activities").body
20
+ end
21
+
22
+ # Returns activities performed on a given user
23
+ #
24
+ # @param user_id [Numeric] The user's id
25
+ # @param options [Hash] Parameters for returning selected activities
26
+ # @return [Hashie::Mash]
27
+ # @example
28
+ # Totter.activity(1)
29
+ def my_activities(user_id, options = DEFAULT_ACTIVITY_OPTIONS)
30
+ get("users/#{user_id}/activities/me").body
31
+ end
32
+
33
+ # Returns activities performed by a user's friends
34
+ #
35
+ # @param user_id [Numeric] The user's id
36
+ # @param options [Hash] Parameters for returning selected activities
37
+ # @return [Hashie::Mash]
38
+ # @example
39
+ # Totter.activity(1)
40
+ def friends_activities(user_id, options = DEFAULT_ACTIVITY_OPTIONS)
41
+ get("users/#{user_id}/activities/friends").body
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -121,7 +121,13 @@ module Totter
121
121
  private
122
122
 
123
123
  def format_timeline_result(http_result)
124
- Hashie::Mash.new(:items => http_result.body, :pusher_channel => http_result.headers['x-pusher-channel'])
124
+ hash = {:items => http_result.body, :pusher_channel => http_result.headers['x-pusher-channel']}
125
+ case @result_format
126
+ when :mashie
127
+ Hashie::Mash.new(hash)
128
+ else
129
+ hash
130
+ end
125
131
  end
126
132
  end
127
133
  end
@@ -100,10 +100,8 @@ module Totter
100
100
  end
101
101
 
102
102
  def json_request(*args)
103
- return Response.new(Hashie::Mash.new(:body => '{}', :headers => [])) if Totter::Client.stubbed?
104
-
105
- # Perform request
106
- Response.new(request(*args))
103
+ # Perform request, pass result format
104
+ Response.new(request(*args), result_format)
107
105
  end
108
106
 
109
107
  def boolean_from_response(*args)
@@ -130,7 +128,8 @@ module Totter
130
128
  # Initializes a new result
131
129
  #
132
130
  # @param http_response [Net::HTTPResponse] the raw response to parse
133
- def initialize(http_response)
131
+ def initialize(http_response, result_format = :mashie)
132
+ @result_format = result_format
134
133
  @headers = parse_headers(http_response.to_hash)
135
134
  @body = parse_body(http_response.body)
136
135
  end
@@ -151,16 +150,18 @@ module Totter
151
150
  # Parse JSON
152
151
  object = MultiJson.load(body)
153
152
 
154
- # Hash
155
- return Hashie::Mash.new(object) if object.is_a? Hash
156
-
157
- # Array
158
- begin
159
- return object.map { |h| Hashie::Mash.new(h) } if object.is_a? Array
160
- rescue
161
- # sometimes, for things like string arrays, we'll end up with an error
153
+ case @result_format
154
+ when :mashie
155
+ # Hash
156
+ return Hashie::Mash.new(object) if object.is_a? Hash
157
+ # Array
158
+ begin
159
+ return object.map { |h| Hashie::Mash.new(h) } if object.is_a? Array
160
+ rescue
161
+ # sometimes, for things like string arrays, we'll end up with an error. Fall through.
162
+ end
162
163
  end
163
- # Fallback incase it's not a hash or array
164
+
164
165
  object
165
166
  end
166
167
  end
@@ -1,4 +1,4 @@
1
1
  module Totter
2
2
  # Verion of the Totter gem
3
- VERSION = '0.3.4'
3
+ VERSION = '0.3.5'
4
4
  end
@@ -0,0 +1,58 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.seesaw.co/v1/configuration
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*'
12
+ User-Agent:
13
+ - Ruby
14
+ Content-Type:
15
+ - application/json
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Cache-Control:
22
+ - max-age=0, private, must-revalidate
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Date:
26
+ - Thu, 04 Apr 2013 22:27:48 GMT
27
+ Etag:
28
+ - ! '"0d93d141645a3ac8841c317bd949da58"'
29
+ Server:
30
+ - thin 1.5.0 codename Knife
31
+ Strict-Transport-Security:
32
+ - max-age=31536000
33
+ X-Rack-Cache:
34
+ - miss
35
+ X-Request-Id:
36
+ - 801bd0cb264f4c1dfc19a74f208981e5
37
+ X-Runtime:
38
+ - '0.004561'
39
+ X-Ua-Compatible:
40
+ - IE=Edge,chrome=1
41
+ Transfer-Encoding:
42
+ - chunked
43
+ Connection:
44
+ - keep-alive
45
+ body:
46
+ encoding: US-ASCII
47
+ string: ! '{"api_version":"v1","view_url":"https://seesaw.co","max_invitiees":0,"socket":{"auth_url":"https://api.seesaw.co/pusher/auth","app_id":27149,"app_key":"9f186e47577d6fa195b4"},"avatar_sizes":[35,70,80,160,320,640],"image_choice_sizes":[100,200,157,307,314,320,624,640],"preferences":{"notifications":[{"key":"notification_friends","text":{"en":"People
48
+ I follow share a decision"}},{"key":"notification_invitee_votes","text":{"en":"People
49
+ I''ve invited vote on my decisions"}},{"key":"notification_following_votes","text":{"en":"People
50
+ I follow vote on my decisions"}},{"key":"notification_other_votes","text":{"en":"People
51
+ I''m not following vote on my decisions"}},{"key":"notification_after_votes","text":{"en":"Others
52
+ vote on a decision I''ve been invited to"}},{"key":"notification_comments","text":{"en":"People
53
+ comment on my decisions"}},{"key":"notification_following","text":{"en":"Someone
54
+ follows me"}},{"key":"notification_mentions","text":{"en":"Someone mentions
55
+ me"}},{"key":"notification_announcements","text":{"en":"System Announcements"}}]},"updated_at":"2013-03-22T11:26:50Z"}'
56
+ http_version:
57
+ recorded_at: Thu, 04 Apr 2013 22:27:48 GMT
58
+ recorded_with: VCR 2.4.0
data/test/test_helper.rb CHANGED
@@ -3,7 +3,9 @@ require 'bundler'
3
3
  Bundler.require :test
4
4
 
5
5
  require 'simplecov'
6
- SimpleCov.start
6
+ SimpleCov.start do
7
+ add_filter "/test/"
8
+ end
7
9
 
8
10
  require 'minitest/autorun'
9
11
  require 'totter'
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+
3
+ class ActivitiesTest < Totter::TestCase
4
+ def test_activity
5
+ stub_request(:get, 'http://localhost:5000/v1/users/4/activities').to_return(:status => 200, :body => "[]")
6
+ result = local_client.activities(4)
7
+ assert_equal 0, result.length
8
+ end
9
+
10
+ def test_my_activity
11
+ stub_request(:get, 'http://localhost:5000/v1/users/4/activities/me').to_return(:status => 200, :body => "[]")
12
+ result = local_client.my_activities(4)
13
+ assert_equal 0, result.length
14
+ end
15
+
16
+ def test_friends_activity
17
+ stub_request(:get, 'http://localhost:5000/v1/users/4/activities/friends').to_return(:status => 200, :body => "[]")
18
+ result = local_client.friends_activities(4)
19
+ assert_equal 0, result.length
20
+ end
21
+ end
@@ -7,7 +7,7 @@ class ConfigurationTest < Totter::TestCase
7
7
  end
8
8
  end
9
9
 
10
- def test_configuration
10
+ def test_explore
11
11
  VCR.use_cassette 'configuration/explore' do
12
12
  assert_equal 2, Totter.explore.timelines.length
13
13
  end
@@ -29,27 +29,19 @@ class ClientTest < Totter::TestCase
29
29
  refute client.ssl?
30
30
  end
31
31
 
32
- def test_stub!
33
- client = Totter::Client.new
34
- Totter::Client.stub!
35
-
36
- assert Totter::Client.stubbed?
37
- expected = {}
38
- assert_equal expected, client.create_decision(1)
39
-
40
- Totter::Client.unstub!
41
- end
42
-
43
32
  def test_configuration
44
33
  Totter::Client.configure do |client|
45
34
  client.api_host = 'blah'
46
35
  client.api_scheme = 'gopher'
36
+ client.result_format = :hash
47
37
  end
48
38
 
49
39
  assert_equal 'blah', Totter::Client.new.api_host
50
40
  assert_equal 'gopher', Totter::Client.new.api_scheme
41
+ Totter::Client.new.result_format
51
42
 
52
43
  # forcibly reset the configuration
53
44
  Totter::Client.options = nil
54
45
  end
46
+
55
47
  end
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+
3
+ class HttpTest < Totter::TestCase
4
+ def test_default_mashie_format
5
+ VCR.use_cassette 'client_http/configuration' do
6
+ assert_equal Hashie::Mash, Totter.configuration.class
7
+ end
8
+ end
9
+
10
+ def test_default_mashie_format
11
+ VCR.use_cassette 'client_http/configuration' do
12
+ assert_equal Hash, Totter.new(result_format: :hash).configuration.class
13
+ end
14
+ end
15
+
16
+ end
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: totter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Sam Soffes
@@ -10,11 +11,12 @@ authors:
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2013-03-18 00:00:00.000000000 Z
14
+ date: 2013-04-04 00:00:00.000000000 Z
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: multi_json
17
18
  requirement: !ruby/object:Gem::Requirement
19
+ none: false
18
20
  requirements:
19
21
  - - ~>
20
22
  - !ruby/object:Gem::Version
@@ -22,6 +24,7 @@ dependencies:
22
24
  type: :runtime
23
25
  prerelease: false
24
26
  version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
25
28
  requirements:
26
29
  - - ~>
27
30
  - !ruby/object:Gem::Version
@@ -29,6 +32,7 @@ dependencies:
29
32
  - !ruby/object:Gem::Dependency
30
33
  name: hashie
31
34
  requirement: !ruby/object:Gem::Requirement
35
+ none: false
32
36
  requirements:
33
37
  - - ~>
34
38
  - !ruby/object:Gem::Version
@@ -36,6 +40,7 @@ dependencies:
36
40
  type: :runtime
37
41
  prerelease: false
38
42
  version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
39
44
  requirements:
40
45
  - - ~>
41
46
  - !ruby/object:Gem::Version
@@ -58,6 +63,7 @@ files:
58
63
  - Readme.markdown
59
64
  - lib/totter.rb
60
65
  - lib/totter/client.rb
66
+ - lib/totter/client/activities.rb
61
67
  - lib/totter/client/avatars.rb
62
68
  - lib/totter/client/choices.rb
63
69
  - lib/totter/client/comments.rb
@@ -81,6 +87,7 @@ files:
81
87
  - test/cassettes/choices/create_for_image.yml
82
88
  - test/cassettes/choices/destroy.yml
83
89
  - test/cassettes/choices/show.yml
90
+ - test/cassettes/client_http/configuration.yml
84
91
  - test/cassettes/comments/create.yml
85
92
  - test/cassettes/comments/destroy.yml
86
93
  - test/cassettes/comments/index.yml
@@ -114,6 +121,7 @@ files:
114
121
  - test/cassettes/votes/create.yml
115
122
  - test/support/client_macros.rb
116
123
  - test/test_helper.rb
124
+ - test/totter/client/activities_test.rb
117
125
  - test/totter/client/avatars_test.rb
118
126
  - test/totter/client/choices_test.rb
119
127
  - test/totter/client/comments_test.rb
@@ -125,31 +133,33 @@ files:
125
133
  - test/totter/client/users_test.rb
126
134
  - test/totter/client/votes_test.rb
127
135
  - test/totter/client_test.rb
136
+ - test/totter/transport/http_test.rb
128
137
  - test/totter_test.rb
129
138
  - totter.gemspec
130
139
  homepage: https://github.com/seesawco/totter-rb
131
140
  licenses:
132
141
  - MIT
133
- metadata: {}
134
142
  post_install_message:
135
143
  rdoc_options: []
136
144
  require_paths:
137
145
  - lib
138
146
  required_ruby_version: !ruby/object:Gem::Requirement
147
+ none: false
139
148
  requirements:
140
- - - '>='
149
+ - - ! '>='
141
150
  - !ruby/object:Gem::Version
142
151
  version: 1.8.7
143
152
  required_rubygems_version: !ruby/object:Gem::Requirement
153
+ none: false
144
154
  requirements:
145
- - - '>='
155
+ - - ! '>='
146
156
  - !ruby/object:Gem::Version
147
157
  version: '0'
148
158
  requirements: []
149
159
  rubyforge_project:
150
- rubygems_version: 2.0.0
160
+ rubygems_version: 1.8.23
151
161
  signing_key:
152
- specification_version: 4
162
+ specification_version: 3
153
163
  summary: Ruby gem for working with the Seesaw API.
154
164
  test_files:
155
165
  - test/cassettes/avatars/create.yml
@@ -160,6 +170,7 @@ test_files:
160
170
  - test/cassettes/choices/create_for_image.yml
161
171
  - test/cassettes/choices/destroy.yml
162
172
  - test/cassettes/choices/show.yml
173
+ - test/cassettes/client_http/configuration.yml
163
174
  - test/cassettes/comments/create.yml
164
175
  - test/cassettes/comments/destroy.yml
165
176
  - test/cassettes/comments/index.yml
@@ -193,6 +204,7 @@ test_files:
193
204
  - test/cassettes/votes/create.yml
194
205
  - test/support/client_macros.rb
195
206
  - test/test_helper.rb
207
+ - test/totter/client/activities_test.rb
196
208
  - test/totter/client/avatars_test.rb
197
209
  - test/totter/client/choices_test.rb
198
210
  - test/totter/client/comments_test.rb
@@ -204,5 +216,6 @@ test_files:
204
216
  - test/totter/client/users_test.rb
205
217
  - test/totter/client/votes_test.rb
206
218
  - test/totter/client_test.rb
219
+ - test/totter/transport/http_test.rb
207
220
  - test/totter_test.rb
208
221
  has_rdoc:
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 03da894c649ab5b6964fa4706ced06e1e9611267
4
- data.tar.gz: b0122b38cb1d56a61736d0035218e81f1048428f
5
- SHA512:
6
- metadata.gz: 06e327a8188d254058933565df74521ab9ba9e1a2e5f83efef9e77edc2d37aceb727856e1c5ccc8227515bd6f1dbaa741112c7b468b665bd8fab80b10f25d720
7
- data.tar.gz: 93ac291640eee5a6eebd9ef52c1edad0fd944a66c07054f4fc29cac5ecd63cb93480a386fd7f988bfc677e0afc2c2ab0812a0576637abf6a3cd0a851207f4aed