foursquare2 1.8.0 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Readme.md CHANGED
@@ -30,7 +30,7 @@ See [the documentation](http://rubydoc.info/gems/foursquare2/frames) for a list
30
30
 
31
31
  #### Get information about a user (use 'self' for the authenticated user)
32
32
 
33
- client.user(108914)
33
+ client.user(108914)
34
34
 
35
35
  #### Get information about a venue
36
36
 
@@ -45,7 +45,7 @@ See [the documentation](http://rubydoc.info/gems/foursquare2/frames) for a list
45
45
  client.add_checkin(:venueId => "4b2afcaaf964a5205bb324e3", :broadcast => 'public', :ll => '36.142064,-86.816086', :shout => 'zomg coffee!1!')
46
46
 
47
47
 
48
- #### Search user by tip
48
+ #### Search user by tip
49
49
 
50
50
  client.search_users_by_tip(:ll => '36.142064,-86.816086', :name => 'Marco')
51
51
 
@@ -53,7 +53,7 @@ See [the documentation](http://rubydoc.info/gems/foursquare2/frames) for a list
53
53
 
54
54
  client.user_tips("123456", :query => 'coffee')
55
55
 
56
- #### Search venues by tip
56
+ #### Search venues by tip
57
57
 
58
58
  client.search_venues_by_tip(:ll => '36.142064,-86.816086', :query => 'coffee')
59
59
 
@@ -116,6 +116,7 @@ See [the documentation](http://rubydoc.info/gems/foursquare2/frames) or [foursqu
116
116
  client.flag_venue
117
117
  client.propose_venue_edit
118
118
  client.managed_venues
119
+ client.managed_venue_stats
119
120
  client.add_special
120
121
  client.add_campaign
121
122
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.8.0
1
+ 1.8.1
data/foursquare2.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "foursquare2"
8
- s.version = "1.8.0"
8
+ s.version = "1.8.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Matt Mueller", "Marco Moura"]
12
- s.date = "2012-07-22"
12
+ s.date = "2012-08-19"
13
13
  s.description = "Gives access to all endpoints in version 2 of foursquare's API with syntax that will be familiar to those who used the original foursquare gem by Jeremy Welch."
14
14
  s.email = ["muellermr@gmail.com", "email@marcomoura.com"]
15
15
  s.extra_rdoc_files = [
@@ -41,6 +41,7 @@ Gem::Specification.new do |s|
41
41
  "test/fixtures/campaign_created.json",
42
42
  "test/fixtures/checkin.json",
43
43
  "test/fixtures/error.json",
44
+ "test/fixtures/error_template.json",
44
45
  "test/fixtures/explore_venues.json",
45
46
  "test/fixtures/friend_checkins.json",
46
47
  "test/fixtures/list.json",
@@ -73,6 +74,7 @@ Gem::Specification.new do |s|
73
74
  "test/fixtures/venue_links.json",
74
75
  "test/fixtures/venue_menus.json",
75
76
  "test/fixtures/venue_photos.json",
77
+ "test/fixtures/venue_stats.json",
76
78
  "test/fixtures/venue_tips.json",
77
79
  "test/helper.rb",
78
80
  "test/test_campaigns.rb",
@@ -54,7 +54,7 @@ module Foursquare2
54
54
  response = connection.get("venues/categories")
55
55
  return_error_or_body(response, response.body.response.categories)
56
56
  end
57
-
57
+
58
58
  # Retrieve links for a venue.
59
59
  #
60
60
  # param [String] venue_id The ID of the venue
@@ -150,7 +150,7 @@ module Foursquare2
150
150
  return_error_or_body(response, response.body.response)
151
151
  end
152
152
 
153
- # Suggest venue completions. Returns a list of mini-venues partially matching the search term, near the location.
153
+ # Suggest venue completions. Returns a list of mini-venues partially matching the search term, near the location.
154
154
  #
155
155
  # @param [Hash] options
156
156
  # @option options String :ll - Latitude and longitude in format LAT,LON
@@ -166,7 +166,7 @@ module Foursquare2
166
166
  end
167
167
  return_error_or_body(response, response.body.response)
168
168
  end
169
-
169
+
170
170
  # Retrieve menus for a venue.
171
171
  #
172
172
  # param [String] venue_id The ID of the venue
@@ -175,16 +175,31 @@ module Foursquare2
175
175
  response = connection.get("venues/#{venue_id}/menu")
176
176
  return_error_or_body(response, response.body.response)
177
177
  end
178
-
178
+
179
179
  #
180
180
  #Returns a list of venues managed
181
181
  #
182
-
182
+
183
183
  def managed_venues()
184
184
  response = connection.get do |req|
185
185
  req.url "venues/managed"
186
186
  end
187
187
  return_error_or_body(response, response.body.response.venues)
188
188
  end
189
- end
189
+
190
+ # Get venue stats over a given time range. Client instance should represent an OAuth user who is the venue owner.
191
+ # Note: returns more detailed statistics than the basic stats returned when calling venue(venue_id)
192
+ #
193
+ # param [String] venue_id The ID of the venue managed by the current user
194
+ # @param [Hash] options
195
+ # @option options Integer :startAt - The start of the time range to retrieve stats for (seconds since epoch). If omitted, all-time stats will be returned.
196
+ # @option options Integer :endAt - The end of the time range to retrieve stats for (seconds since epoch). If omitted, the current time is assumed.
197
+
198
+ def managed_venue_stats(venue_id, options={})
199
+ response = connection.get do |req|
200
+ req.url "venues/#{venue_id}/stats", options
201
+ end
202
+ return_error_or_body(response, response.body.response)
203
+ end
204
+ end
190
205
  end
@@ -0,0 +1 @@
1
+ { "meta": { "code": %error_code%, "errorType": "%error_type%", "errorDetail": "%error_message%" } }
@@ -0,0 +1,148 @@
1
+ {
2
+ "meta": {
3
+ "code": 200
4
+ },
5
+ "response": {
6
+ "stats": {
7
+ "totalCheckins": 1,
8
+ "newCheckins": 1,
9
+ "uniqueVisitors": 1,
10
+ "sharing": {
11
+ "twitter": 0,
12
+ "facebook": 0
13
+ },
14
+ "genderBreakdown": {
15
+ "female": 0,
16
+ "male": 1
17
+ },
18
+ "ageBreakdown": [{
19
+ "age": "13-17",
20
+ "checkins": 0
21
+ }, {
22
+ "age": "18-24",
23
+ "checkins": 0
24
+ }, {
25
+ "age": "25-34",
26
+ "checkins": 1
27
+ }, {
28
+ "age": "35-44",
29
+ "checkins": 0
30
+ }, {
31
+ "age": "45-54",
32
+ "checkins": 0
33
+ }, {
34
+ "age": "55+",
35
+ "checkins": 0
36
+ }],
37
+ "hourBreakdown": [{
38
+ "hour": 0,
39
+ "checkins": 1
40
+ }, {
41
+ "hour": 1,
42
+ "checkins": 0
43
+ }, {
44
+ "hour": 2,
45
+ "checkins": 0
46
+ }, {
47
+ "hour": 3,
48
+ "checkins": 0
49
+ }, {
50
+ "hour": 4,
51
+ "checkins": 0
52
+ }, {
53
+ "hour": 5,
54
+ "checkins": 0
55
+ }, {
56
+ "hour": 6,
57
+ "checkins": 0
58
+ }, {
59
+ "hour": 7,
60
+ "checkins": 0
61
+ }, {
62
+ "hour": 8,
63
+ "checkins": 0
64
+ }, {
65
+ "hour": 9,
66
+ "checkins": 0
67
+ }, {
68
+ "hour": 10,
69
+ "checkins": 0
70
+ }, {
71
+ "hour": 11,
72
+ "checkins": 0
73
+ }, {
74
+ "hour": 12,
75
+ "checkins": 0
76
+ }, {
77
+ "hour": 13,
78
+ "checkins": 0
79
+ }, {
80
+ "hour": 14,
81
+ "checkins": 0
82
+ }, {
83
+ "hour": 15,
84
+ "checkins": 0
85
+ }, {
86
+ "hour": 16,
87
+ "checkins": 0
88
+ }, {
89
+ "hour": 17,
90
+ "checkins": 0
91
+ }, {
92
+ "hour": 18,
93
+ "checkins": 0
94
+ }, {
95
+ "hour": 19,
96
+ "checkins": 0
97
+ }, {
98
+ "hour": 20,
99
+ "checkins": 0
100
+ }, {
101
+ "hour": 21,
102
+ "checkins": 0
103
+ }, {
104
+ "hour": 22,
105
+ "checkins": 0
106
+ }, {
107
+ "hour": 23,
108
+ "checkins": 0
109
+ }],
110
+ "visitCountHistogram": [{
111
+ "checkins": 1,
112
+ "users": 1
113
+ }],
114
+ "topVisitors": [{
115
+ "user": {
116
+ "id": "4372259",
117
+ "firstName": "Murugan",
118
+ "lastName": "V.",
119
+ "photo": "https://is1.4sqi.net/userpix_thumbs/2QVZXGQQA2LILWY3.jpg",
120
+ "tips": {
121
+ "count": 2
122
+ },
123
+ "gender": "male",
124
+ "homeCity": "Chennai, India",
125
+ "bio": "",
126
+ "contact": {}
127
+ },
128
+ "checkins": 1
129
+ }],
130
+ "recentVisitors": [{
131
+ "user": {
132
+ "id": "4372259",
133
+ "firstName": "Murugan",
134
+ "lastName": "V.",
135
+ "photo": "https://is1.4sqi.net/userpix_thumbs/2QVZXGQQA2LILWY3.jpg",
136
+ "tips": {
137
+ "count": 2
138
+ },
139
+ "gender": "male",
140
+ "homeCity": "Chennai, India",
141
+ "bio": "",
142
+ "contact": {}
143
+ },
144
+ "lastCheckin": 1338182425
145
+ }]
146
+ }
147
+ }
148
+ }
data/test/helper.rb CHANGED
@@ -46,7 +46,7 @@ end
46
46
 
47
47
  def stub_get(url, filename, options={})
48
48
  opts = {
49
- :body => fixture_file(filename),
49
+ :body => error_or_standard_body(filename, options),
50
50
  :content_type => 'application/json; charset=utf-8'
51
51
  }.merge(options)
52
52
  FakeWeb.register_uri(:get, foursquare_url(url), opts)
@@ -54,11 +54,20 @@ end
54
54
 
55
55
  def stub_post(url, filename, options={})
56
56
  opts = {
57
- :body => fixture_file(filename),
57
+ :body => error_or_standard_body(filename, options),
58
58
  :content_type => 'application/json; charset=utf-8'
59
59
  }.merge(options)
60
60
  FakeWeb.register_uri(:post, foursquare_url(url), opts)
61
61
  end
62
62
 
63
+ def error_or_standard_body(filename, options)
64
+ error_options = options.delete(:error)
65
+ body = fixture_file(error_options ? 'error_template.json' : filename)
66
+ body = body.gsub(/%error_code%/, error_options[:code])
67
+ .gsub(/%error_type%/, error_options[:type])
68
+ .gsub(/%error_message%/, error_options[:message]) if error_options
69
+ body
70
+ end
71
+
63
72
  class Test::Unit::TestCase
64
73
  end
data/test/test_venues.rb CHANGED
@@ -41,7 +41,7 @@ class TestVenues < Test::Unit::TestCase
41
41
 
42
42
  should "get tips from a venue only with some term" do
43
43
  stub_get("https://api.foursquare.com/v2/venues/4c94a45c82b56dcb47cad0aa/tips?oauth_token=#{@client.oauth_token}", "venue_tips.json")
44
- tips = @client.venue_tips('4c94a45c82b56dcb47cad0aa', {:query => "legal"})
44
+ tips = @client.venue_tips('4c94a45c82b56dcb47cad0aa', {:query => "legal"})
45
45
  tips[:count].should == 1
46
46
  tips.items.first.id.should == "4c94a45c82b56dcb47cad0aa"
47
47
  end
@@ -60,7 +60,7 @@ class TestVenues < Test::Unit::TestCase
60
60
 
61
61
  tips[:items].size.should == 0
62
62
  end
63
-
63
+
64
64
  should "allow venues to be explored" do
65
65
  stub_get("https://api.foursquare.com/v2/venues/explore?section=food&ll=40.7%2C-74&oauth_token=#{@client.oauth_token}&limit=2", "explore_venues.json")
66
66
  venues = @client.explore_venues(:ll => '40.7,-74', :section => 'food', :limit => '2')
@@ -74,7 +74,7 @@ class TestVenues < Test::Unit::TestCase
74
74
  links.items.size == links.count
75
75
  links.items.size.should == 2
76
76
  end
77
-
77
+
78
78
  should "get photos for a venue" do
79
79
  stub_get("https://api.foursquare.com/v2/venues/4b8c3d87f964a520f7c532e3/photos?group=venue&oauth_token=#{@client.oauth_token}&limit=3", "venue_photos.json")
80
80
  photos = @client.venue_photos('4b8c3d87f964a520f7c532e3', { :group => 'venue', :limit => 3 })
@@ -88,7 +88,7 @@ class TestVenues < Test::Unit::TestCase
88
88
  venues = @client.suggest_completion_venues(:ll => "40.7,-74", :query => "coffee")
89
89
  venues.minivenues.first.id.should == '44dc96e4f964a520b0361fe3'
90
90
  end
91
-
91
+
92
92
  should "fetch venue for manager" do
93
93
  stub_get("https://api.foursquare.com/v2/venues/managed?oauth_token=#{@client.oauth_token}", "managed_venues.json")
94
94
  venues = @client.managed_venues()
@@ -104,6 +104,28 @@ class TestVenues < Test::Unit::TestCase
104
104
  response.menu.menus.items.first['entries']['items'].first['entries'].items.count.should == 11
105
105
  end
106
106
 
107
+ should "get detailed stats for a venue managed by user" do
108
+ stub_get("https://api.foursquare.com/v2/venues/4b8c3d87f964a520f7c532e3/stats?oauth_token=#{@client.oauth_token}", "venue_stats.json")
109
+ response = @client.managed_venue_stats('4b8c3d87f964a520f7c532e3')
110
+ response.stats.totalCheckins.should == 1
111
+ end
112
+
113
+ should "get a subset of detailed stats for a venue managed by user when passing in options" do
114
+ stub_get("https://api.foursquare.com/v2/venues/4b8c3d87f964a520f7c532e3/stats?oauth_token=#{@client.oauth_token}&startAt=1343085269&endAt=1343171627", "venue_stats.json")
115
+ response = @client.managed_venue_stats('4b8c3d87f964a520f7c532e3', { :startAt => 1343085269, :endAt => 1343171627})
116
+ response.stats.totalCheckins.should == 1
117
+ end
118
+
119
+ context "and getting detailed stats for a venue not managed by user" do
120
+ should "raise a 'not authorized' API error" do
121
+ stub_get("https://api.foursquare.com/v2/venues/4ad4c04af964a52065f220e3/stats?oauth_token=#{@client.oauth_token}", nil,
122
+ :error => { :code => '403', :type => 'not_authorized', :message => 'User is not authorized to view venue stats' })
123
+ assert_raises(Foursquare2::APIError) do
124
+ @client.managed_venue_stats('4ad4c04af964a52065f220e3')
125
+ end
126
+ end
127
+ end
128
+
107
129
  end
108
130
 
109
131
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foursquare2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.8.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-07-22 00:00:00.000000000Z
13
+ date: 2012-08-19 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday
17
- requirement: &70215631196980 !ruby/object:Gem::Requirement
17
+ requirement: &70129938827720 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0.8'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70215631196980
25
+ version_requirements: *70129938827720
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: faraday_middleware
28
- requirement: &70215631193980 !ruby/object:Gem::Requirement
28
+ requirement: &70129938826180 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0.8'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70215631193980
36
+ version_requirements: *70129938826180
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: hashie
39
- requirement: &70215631187100 !ruby/object:Gem::Requirement
39
+ requirement: &70129938824040 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '1.0'
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *70215631187100
47
+ version_requirements: *70129938824040
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: awesome_print
50
- requirement: &70215631181060 !ruby/object:Gem::Requirement
50
+ requirement: &70129938809900 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70215631181060
58
+ version_requirements: *70129938809900
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: shoulda
61
- requirement: &70215631173680 !ruby/object:Gem::Requirement
61
+ requirement: &70129938807520 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70215631173680
69
+ version_requirements: *70129938807520
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: bundler
72
- requirement: &70215631252540 !ruby/object:Gem::Requirement
72
+ requirement: &70129938805700 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ~>
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: '1.0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *70215631252540
80
+ version_requirements: *70129938805700
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: jeweler
83
- requirement: &70215639898860 !ruby/object:Gem::Requirement
83
+ requirement: &70129938803120 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ~>
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: '1.5'
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *70215639898860
91
+ version_requirements: *70129938803120
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: rcov
94
- requirement: &70215640489100 !ruby/object:Gem::Requirement
94
+ requirement: &70129938801720 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ! '>='
@@ -99,10 +99,10 @@ dependencies:
99
99
  version: '0'
100
100
  type: :development
101
101
  prerelease: false
102
- version_requirements: *70215640489100
102
+ version_requirements: *70129938801720
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: fakeweb
105
- requirement: &70215640804220 !ruby/object:Gem::Requirement
105
+ requirement: &70129938799960 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
108
  - - ~>
@@ -110,10 +110,10 @@ dependencies:
110
110
  version: '1.3'
111
111
  type: :development
112
112
  prerelease: false
113
- version_requirements: *70215640804220
113
+ version_requirements: *70129938799960
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: jnunemaker-matchy
116
- requirement: &70215641074800 !ruby/object:Gem::Requirement
116
+ requirement: &70129938798420 !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements:
119
119
  - - ~>
@@ -121,10 +121,10 @@ dependencies:
121
121
  version: '0.4'
122
122
  type: :development
123
123
  prerelease: false
124
- version_requirements: *70215641074800
124
+ version_requirements: *70129938798420
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: json_pure
127
- requirement: &70215641073740 !ruby/object:Gem::Requirement
127
+ requirement: &70129938796880 !ruby/object:Gem::Requirement
128
128
  none: false
129
129
  requirements:
130
130
  - - ~>
@@ -132,10 +132,10 @@ dependencies:
132
132
  version: '1.4'
133
133
  type: :development
134
134
  prerelease: false
135
- version_requirements: *70215641073740
135
+ version_requirements: *70129938796880
136
136
  - !ruby/object:Gem::Dependency
137
137
  name: multi_json
138
- requirement: &70215641072600 !ruby/object:Gem::Requirement
138
+ requirement: &70129938795140 !ruby/object:Gem::Requirement
139
139
  none: false
140
140
  requirements:
141
141
  - - <
@@ -146,7 +146,7 @@ dependencies:
146
146
  version: 0.0.5
147
147
  type: :development
148
148
  prerelease: false
149
- version_requirements: *70215641072600
149
+ version_requirements: *70129938795140
150
150
  description: Gives access to all endpoints in version 2 of foursquare's API with syntax
151
151
  that will be familiar to those who used the original foursquare gem by Jeremy Welch.
152
152
  email:
@@ -182,6 +182,7 @@ files:
182
182
  - test/fixtures/campaign_created.json
183
183
  - test/fixtures/checkin.json
184
184
  - test/fixtures/error.json
185
+ - test/fixtures/error_template.json
185
186
  - test/fixtures/explore_venues.json
186
187
  - test/fixtures/friend_checkins.json
187
188
  - test/fixtures/list.json
@@ -214,6 +215,7 @@ files:
214
215
  - test/fixtures/venue_links.json
215
216
  - test/fixtures/venue_menus.json
216
217
  - test/fixtures/venue_photos.json
218
+ - test/fixtures/venue_stats.json
217
219
  - test/fixtures/venue_tips.json
218
220
  - test/helper.rb
219
221
  - test/test_campaigns.rb
@@ -241,7 +243,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
241
243
  version: '0'
242
244
  segments:
243
245
  - 0
244
- hash: -1840967499921104058
246
+ hash: 1196371132867193506
245
247
  required_rubygems_version: !ruby/object:Gem::Requirement
246
248
  none: false
247
249
  requirements: