totter 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .ruby-version
data/.travis.yml CHANGED
@@ -1,4 +1,6 @@
1
1
  language: ruby
2
2
  bundler_args: --without development
3
3
  rvm:
4
+ - 1.8.7
4
5
  - 1.9.3
6
+ - 2.0.0
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
3
3
  # Gem dependencies
4
4
  gemspec
5
5
 
6
- gem 'rake', group: [:development, :test]
6
+ gem 'rake', :group => [:development, :test]
7
7
 
8
8
  # Development dependencies
9
9
  group :development do
@@ -14,9 +14,9 @@ end
14
14
  # Testing dependencies
15
15
  group :test do
16
16
  gem 'minitest'
17
- gem 'minitest-wscolor'
18
- gem 'webmock', require: 'webmock/minitest'
17
+ gem 'turn'
18
+ gem 'webmock', :require => 'webmock/minitest'
19
19
  gem 'vcr'
20
- gem 'mocha', require: 'mocha/setup'
21
- gem 'simplecov', require: false
20
+ gem 'mocha', :require => 'mocha/setup'
21
+ gem 'simplecov', :require => false
22
22
  end
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ Rake::TestTask.new(:test) do |t|
6
6
  t.libs << 'test'
7
7
  t.pattern = 'test/**/*_test.rb'
8
8
  end
9
- task default: :test
9
+ task :default => :test
10
10
 
11
11
  begin
12
12
  require 'yard'
data/lib/totter/client.rb CHANGED
@@ -29,7 +29,7 @@ module Totter
29
29
  #
30
30
  # @param options [Hash] optionally specify `:access_token`, `:api_scheme`, `:api_host`, `:api_version`, `:client_token`, or `:transport`.
31
31
  def initialize(options = {})
32
- options = { access_token: options } if options.is_a? String
32
+ options = { :access_token => options } if options.is_a? String
33
33
 
34
34
  @access_token = options[:access_token] if options[:access_token]
35
35
  @api_scheme = (options[:api_scheme] or 'https')
@@ -65,14 +65,17 @@ module Totter
65
65
  @api_scheme == 'https'
66
66
  end
67
67
 
68
+ # Turns on stubbing. When called, all HTTP API calls will return an empty response
68
69
  def self.stub!
69
70
  @@stubbed = true
70
71
  end
71
72
 
73
+ # Turns off stubing. Once called, HTTP requests will be sent as normal
72
74
  def self.unstub!
73
75
  @@stubbed = false
74
76
  end
75
77
 
78
+ # Returns the current status of HTTP stubbing
76
79
  def self.stubbed?
77
80
  @@stubbed
78
81
  end
@@ -32,13 +32,13 @@ module Totter
32
32
  raise ArgumentError.new('image_url option is required') unless options[:image_url]
33
33
 
34
34
  data = {
35
- choice: {
36
- type: 'image',
37
- image_url: options[:image_url],
38
- subject: options[:subject],
39
- meta: {
40
- link_url: options[:link_url],
41
- link_title: options[:link_title]
35
+ :choice => {
36
+ :type => 'image',
37
+ :image_url => options[:image_url],
38
+ :subject => options[:subject],
39
+ :meta => {
40
+ :link_url => options[:link_url],
41
+ :link_title => options[:link_title]
42
42
  }
43
43
  }
44
44
  }
@@ -23,8 +23,8 @@ module Totter
23
23
  # Totter.create_comment(1, 1, 'I love boots!')
24
24
  def create_comment(user_id, decision_id, message)
25
25
  options = {
26
- comment: {
27
- message: message
26
+ :comment => {
27
+ :message => message
28
28
  }
29
29
  }
30
30
  post("users/#{user_id}/decisions/#{decision_id}/comments", options).body
@@ -37,7 +37,7 @@ module Totter
37
37
  # Totter.publish_decision(1, 1, question: 'Why is the sky blue?')
38
38
  def publish_decision(user_id, decision_id, options = {})
39
39
  decision_options = {
40
- decision: options
40
+ :decision => options
41
41
  }
42
42
 
43
43
  post("users/#{user_id}/decisions/#{decision_id}/publish", decision_options).body
@@ -4,7 +4,7 @@ module Totter
4
4
  module Timelines
5
5
  # Default options sent with every timeline request unless otherwise specified.
6
6
  DEFAULT_TIMELINE_OPTIONS = {
7
- limit: 20
7
+ :limit => 20
8
8
  }
9
9
 
10
10
  # Get recent decisions from the global timeline.
@@ -31,7 +31,7 @@ module Totter
31
31
  # @example
32
32
  # Totter.global_timeline(limit: 20, since: '1,15')
33
33
  def hashtag_timeline(hashtag, options = DEFAULT_TIMELINE_OPTIONS)
34
- format_timeline_result get('timelines/global', options.merge({hashtag: hashtag}))
34
+ format_timeline_result get('timelines/global', options.merge({:hashtag => hashtag}))
35
35
  end
36
36
 
37
37
  # Get recent decisions from a sticker timeline
@@ -45,7 +45,7 @@ module Totter
45
45
  # @example
46
46
  # Totter.global_timeline(limit: 20, since: '1,15')
47
47
  def sticker_timeline(sticker, options = DEFAULT_TIMELINE_OPTIONS)
48
- format_timeline_result get('timelines/global', options.merge({sticker: sticker}))
48
+ format_timeline_result get('timelines/global', options.merge({:sticker => sticker}))
49
49
  end
50
50
 
51
51
  # Search for published items
@@ -59,7 +59,7 @@ module Totter
59
59
  # @example
60
60
  # Totter.global_timeline(limit: 20, since: '1,15')
61
61
  def search_timeline(query, options = DEFAULT_TIMELINE_OPTIONS)
62
- format_timeline_result get('timelines/search', options.merge({query: query}))
62
+ format_timeline_result get('timelines/search', options.merge({:query => query}))
63
63
  end
64
64
 
65
65
  # Get recent decisions from the flagged-for-review timeline
@@ -106,10 +106,10 @@ module Totter
106
106
  format_timeline_result get("users/#{user_id}/timelines/friends", options)
107
107
  end
108
108
 
109
- private
109
+ private
110
110
 
111
111
  def format_timeline_result(http_result)
112
- Hashie::Mash.new(items: http_result.body, pusher_channel: http_result.headers['x-pusher-channel'])
112
+ Hashie::Mash.new(:items => http_result.body, :pusher_channel => http_result.headers['x-pusher-channel'])
113
113
  end
114
114
  end
115
115
  end
@@ -41,7 +41,7 @@ module Totter
41
41
  # @option preferences [Boolean] :notification_following Notify when other_user starts follwing user
42
42
  def update_me(options = {}, preferences = {})
43
43
  data = {
44
- user: options.merge({preferences: preferences})
44
+ :user => options.merge({:preferences => preferences})
45
45
  }
46
46
  put("me", data).body
47
47
  end
@@ -13,10 +13,10 @@ module Totter
13
13
  raise UniqueIDRequired unless unique_id or self.authenticated?
14
14
 
15
15
  path = "users/#{decision_user_id}/decisions/#{decision_id}/votes"
16
- params = { choice_id: choice_id, unique_id: unique_id }
16
+ params = { :choice_id => choice_id, :unique_id => unique_id }
17
17
 
18
18
  slug = options[:invitation_slug]
19
- params[:invitation] = { slug: slug } if slug
19
+ params[:invitation] = { :slug => slug } if slug
20
20
 
21
21
  post(path, params).body
22
22
  end
@@ -5,7 +5,7 @@ module Totter
5
5
 
6
6
  # Transport adapter map
7
7
  TRANSPORT_MAP = {
8
- http: Totter::Transport::HTTP
8
+ :http => Totter::Transport::HTTP
9
9
  }
10
10
  end
11
11
  end
@@ -1,3 +1,4 @@
1
+
1
2
  module Totter
2
3
  module Transport
3
4
  # Default HTTP API transport adapter
@@ -25,7 +26,7 @@ module Totter
25
26
  # if the request requires parameters in the query string, merge them in
26
27
  if params and !can_post_data?(method)
27
28
  query_values = uri.query ? URI.decode_www_form(uri.query).inject({}) {|h,(k,v)| h[k]=v; h} : {}
28
- uri.query = URI.encode_www_form (query_values || {}).merge(params)
29
+ uri.query = to_url_params((query_values || {}).merge(params))
29
30
  end
30
31
 
31
32
  # Build request
@@ -62,6 +63,27 @@ module Totter
62
63
  end
63
64
  end
64
65
 
66
+ def to_url_params(hash)
67
+ params = []
68
+ hash.each_pair do |key, value|
69
+ params << param_for(key, value).flatten
70
+ end
71
+ params.sort.join('&')
72
+ end
73
+
74
+ def param_for(key, value, parent = nil)
75
+ if value.is_a?(Hash)
76
+ params = []
77
+ value.each_pair do |value_key, value_value|
78
+ value_parent = parent ? parent + "[#{key}]" : key.to_s
79
+ params << param_for(value_key, value_value, value_parent)
80
+ end
81
+ params
82
+ else
83
+ ["#{parent ? parent + "[#{key}]" : key.to_s}=#{CGI::escape(value.to_s)}"]
84
+ end
85
+ end
86
+
65
87
  def handle_error(response)
66
88
  # Find error or return
67
89
  return unless error = Totter::ERROR_MAP[response.code.to_i]
@@ -78,7 +100,7 @@ module Totter
78
100
  end
79
101
 
80
102
  def json_request(*args)
81
- return Response.new(Hashie::Mash.new(body: {}.to_json, headers: [])) if Totter::Client.stubbed?
103
+ return Response.new(Hashie::Mash.new(:body => '{}', :headers => [])) if Totter::Client.stubbed?
82
104
 
83
105
  # Perform request
84
106
  Response.new(request(*args))
@@ -99,9 +121,15 @@ module Totter
99
121
  end
100
122
  end
101
123
 
124
+ # Response class responsible for deserializing API calls
125
+ # @attr [Object] body The parsed response
126
+ # @attr [Hash] headers HTTP headers returned as part of the response
102
127
  class Response
103
128
  attr_accessor :body, :headers
104
129
 
130
+ # Initializes a new result
131
+ #
132
+ # @param http_response [Net::HTTPResponse] the raw response to parse
105
133
  def initialize(http_response)
106
134
  @headers = parse_headers(http_response.to_hash)
107
135
  @body = parse_body(http_response.body)
@@ -109,13 +137,16 @@ module Totter
109
137
 
110
138
  private
111
139
 
140
+ # Parses raw headers in to a reasonable hash
112
141
  def parse_headers(raw_headers)
142
+ # raw headers from net_http have an array for each result. Flatten them out.
113
143
  raw_headers.inject({}) do |remainder, (k, v)|
114
144
  remainder[k] = [v].flatten.first
115
145
  remainder
116
146
  end
117
147
  end
118
148
 
149
+ # Parses the raw body in to a Hashie::Mash object, an array of Hashie::Mashes, or, if all else fails, returns a hash.
119
150
  def parse_body(body)
120
151
  # Parse JSON
121
152
  object = MultiJson.load(body)
@@ -1,4 +1,4 @@
1
1
  module Totter
2
2
  # Verion of the Totter gem
3
- VERSION = '0.3.1'
3
+ VERSION = '0.3.2'
4
4
  end
@@ -1,5 +1,5 @@
1
1
  module ClientMacros
2
2
  def local_client
3
- client = Totter::Client.new(access_token: '9774e653f7b3c1de5f21b61adc08ba24', api_host: 'localhost:5000', api_scheme: 'http')
3
+ client = Totter::Client.new(:access_token => '9774e653f7b3c1de5f21b61adc08ba24', :api_host => 'localhost:5000', :api_scheme => 'http')
4
4
  end
5
5
  end
@@ -12,11 +12,11 @@ class ChoicesTest < Totter::TestCase
12
12
  def test_create_choice_for_image
13
13
  VCR.use_cassette 'choices/create_for_image' do
14
14
  client = local_client
15
- data = {
16
- image_url: 'http://recess.s3.amazonaws.com/default_avatars/v1/photo_1.png',
17
- subject: 'Test Image',
18
- link_url: 'http://seesaw.co',
19
- link_title: 'Seesaw'
15
+ data = {
16
+ :image_url => 'http://recess.s3.amazonaws.com/default_avatars/v1/photo_1.png',
17
+ :subject => 'Test Image',
18
+ :link_url => 'http://seesaw.co',
19
+ :link_title => 'Seesaw'
20
20
  }
21
21
  decision = client.create_decision(1)
22
22
  choice = client.create_choice_for_image(decision.user_id, decision.id, data)
@@ -23,7 +23,7 @@ class DecisionsTest < Totter::TestCase
23
23
  client = local_client
24
24
  decision = client.create_decision(1)
25
25
  choice = create_test_choice(client, decision.user_id, decision.id)
26
- result = client.publish_decision(decision.user_id, decision.id, question: 'Why is the sky blue?')
26
+ result = client.publish_decision(decision.user_id, decision.id, :question => 'Why is the sky blue?')
27
27
  assert result.published_at
28
28
  assert 1, result.choices.length
29
29
  end
@@ -67,10 +67,10 @@ class DecisionsTest < Totter::TestCase
67
67
 
68
68
  def create_test_choice(client, user_id, decision_id)
69
69
  data = {
70
- image_url: 'http://recess.s3.amazonaws.com/default_avatars/v1/photo_1.png',
71
- subject: 'Test Image',
72
- link_url: 'http://seesaw.co',
73
- link_title: 'Seesaw'
70
+ :image_url => 'http://recess.s3.amazonaws.com/default_avatars/v1/photo_1.png',
71
+ :subject => 'Test Image',
72
+ :link_url => 'http://seesaw.co',
73
+ :link_title => 'Seesaw'
74
74
  }
75
75
  client.create_choice_for_image(user_id, decision_id, data)
76
76
  end
@@ -3,7 +3,7 @@ require 'test_helper'
3
3
  class TimelinesTest < Totter::TestCase
4
4
  def test_global
5
5
  VCR.use_cassette 'timelines/global' do
6
- response = Totter.global_timeline(limit: 15)
6
+ response = Totter.global_timeline(:limit => 15)
7
7
  assert_equal 15, response.items.length
8
8
  assert_equal 'timeline-global', response.pusher_channel
9
9
  end
@@ -20,11 +20,11 @@ class UsersTest < Totter::TestCase
20
20
  VCR.use_cassette 'users/update' do
21
21
  client = local_client
22
22
  options = {
23
- given_name: "Aaron",
24
- family_name: 'Gotwalt'
23
+ :given_name => "Aaron",
24
+ :family_name => 'Gotwalt'
25
25
  }
26
26
  preferences = {
27
- notification_comments: false
27
+ :notification_comments => false
28
28
  }
29
29
 
30
30
  result = client.update_me(options, preferences)
@@ -3,12 +3,12 @@ require 'test_helper'
3
3
  class VotesTest < Totter::TestCase
4
4
  def test_create_vote
5
5
  VCR.use_cassette 'votes/create' do
6
- vote = Totter.create_vote(5, 3276, 5381, unique_id: '021a997')
6
+ vote = Totter.create_vote(5, 3276, 5381, :unique_id => '021a997')
7
7
  assert_equal 5381, vote.choice_id
8
8
 
9
9
  # Prevent duplicates
10
10
  assert_raises Totter::BadRequest do
11
- Totter.create_vote(5, 3276, 5381, unique_id: '021a997')
11
+ Totter.create_vote(5, 3276, 5381, :unique_id => '021a997')
12
12
  end
13
13
  end
14
14
  end
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
 
3
3
  class ClientTest < Totter::TestCase
4
4
  def test_initialization
5
- client = Totter::Client.new(access_token: 'asdf1234')
5
+ client = Totter::Client.new(:access_token => 'asdf1234')
6
6
  assert_equal 'asdf1234', client.access_token
7
7
  assert client.authenticated?
8
8
 
@@ -17,7 +17,7 @@ class ClientTest < Totter::TestCase
17
17
  client = Totter::Client.new
18
18
  assert_equal 'https://api.seesaw.co/v1/', client.base_url
19
19
 
20
- client = Totter::Client.new(api_scheme: 'http', api_host: 'example.com', api_version: 42)
20
+ client = Totter::Client.new(:api_scheme => 'http', :api_host => 'example.com', :api_version => 42)
21
21
  assert_equal 'http://example.com/v42/', client.base_url
22
22
  end
23
23
 
@@ -25,7 +25,7 @@ class ClientTest < Totter::TestCase
25
25
  client = Totter::Client.new
26
26
  assert client.ssl?
27
27
 
28
- client = Totter::Client.new(api_scheme: 'http')
28
+ client = Totter::Client.new(:api_scheme => 'http')
29
29
  refute client.ssl?
30
30
  end
31
31
 
data/totter.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ['lib']
20
20
 
21
- gem.required_ruby_version = '>= 1.9.2'
21
+ gem.required_ruby_version = '>= 1.8.7'
22
22
  gem.add_dependency 'multi_json', '~> 1.5.0'
23
23
  gem.add_dependency 'hashie', '~> 1.2.0'
24
24
  end
metadata CHANGED
@@ -1,59 +1,69 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: totter
3
- version: !ruby/object:Gem::Version
4
- version: 0.3.1
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 2
10
+ version: 0.3.2
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Sam Soffes
9
14
  - Aaron Gotwalt
10
15
  - Adam Ryan
11
16
  autorequire:
12
17
  bindir: bin
13
18
  cert_chain: []
14
- date: 2013-02-20 00:00:00.000000000 Z
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
19
+
20
+ date: 2013-02-25 00:00:00 -05:00
21
+ default_executable:
22
+ dependencies:
23
+ - !ruby/object:Gem::Dependency
17
24
  name: multi_json
18
- requirement: !ruby/object:Gem::Requirement
19
- none: false
20
- requirements:
21
- - - ~>
22
- - !ruby/object:Gem::Version
23
- version: 1.5.0
24
- type: :runtime
25
25
  prerelease: false
26
- version_requirements: !ruby/object:Gem::Requirement
26
+ requirement: &id001 !ruby/object:Gem::Requirement
27
27
  none: false
28
- requirements:
28
+ requirements:
29
29
  - - ~>
30
- - !ruby/object:Gem::Version
30
+ - !ruby/object:Gem::Version
31
+ hash: 3
32
+ segments:
33
+ - 1
34
+ - 5
35
+ - 0
31
36
  version: 1.5.0
32
- - !ruby/object:Gem::Dependency
33
- name: hashie
34
- requirement: !ruby/object:Gem::Requirement
35
- none: false
36
- requirements:
37
- - - ~>
38
- - !ruby/object:Gem::Version
39
- version: 1.2.0
40
37
  type: :runtime
38
+ version_requirements: *id001
39
+ - !ruby/object:Gem::Dependency
40
+ name: hashie
41
41
  prerelease: false
42
- version_requirements: !ruby/object:Gem::Requirement
42
+ requirement: &id002 !ruby/object:Gem::Requirement
43
43
  none: false
44
- requirements:
44
+ requirements:
45
45
  - - ~>
46
- - !ruby/object:Gem::Version
46
+ - !ruby/object:Gem::Version
47
+ hash: 31
48
+ segments:
49
+ - 1
50
+ - 2
51
+ - 0
47
52
  version: 1.2.0
53
+ type: :runtime
54
+ version_requirements: *id002
48
55
  description: Ruby gem for working with the Seesaw API.
49
- email:
56
+ email:
50
57
  - sam@soff.es
51
58
  - gotwalt@gmail.com
52
59
  - adam.g.ryan@gmail.com
53
60
  executables: []
61
+
54
62
  extensions: []
63
+
55
64
  extra_rdoc_files: []
56
- files:
65
+
66
+ files:
57
67
  - .gitignore
58
68
  - .travis.yml
59
69
  - Contributing.markdown
@@ -129,32 +139,43 @@ files:
129
139
  - test/totter/client_test.rb
130
140
  - test/totter_test.rb
131
141
  - totter.gemspec
142
+ has_rdoc: true
132
143
  homepage: https://github.com/seesawco/totter-rb
133
- licenses:
144
+ licenses:
134
145
  - MIT
135
146
  post_install_message:
136
147
  rdoc_options: []
137
- require_paths:
148
+
149
+ require_paths:
138
150
  - lib
139
- required_ruby_version: !ruby/object:Gem::Requirement
151
+ required_ruby_version: !ruby/object:Gem::Requirement
140
152
  none: false
141
- requirements:
142
- - - ! '>='
143
- - !ruby/object:Gem::Version
144
- version: 1.9.2
145
- required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ hash: 57
157
+ segments:
158
+ - 1
159
+ - 8
160
+ - 7
161
+ version: 1.8.7
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
163
  none: false
147
- requirements:
148
- - - ! '>='
149
- - !ruby/object:Gem::Version
150
- version: '0'
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ hash: 3
168
+ segments:
169
+ - 0
170
+ version: "0"
151
171
  requirements: []
172
+
152
173
  rubyforge_project:
153
- rubygems_version: 1.8.23
174
+ rubygems_version: 1.6.2
154
175
  signing_key:
155
176
  specification_version: 3
156
177
  summary: Ruby gem for working with the Seesaw API.
157
- test_files:
178
+ test_files:
158
179
  - test/cassettes/avatars/create.yml
159
180
  - test/cassettes/avatars/destroy.yml
160
181
  - test/cassettes/avatars/index.yml
@@ -205,4 +226,3 @@ test_files:
205
226
  - test/totter/client/votes_test.rb
206
227
  - test/totter/client_test.rb
207
228
  - test/totter_test.rb
208
- has_rdoc: