the-city-admin 0.2.1 → 0.3.0
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/lib/common.rb +2 -1
- data/lib/readers/api_reader.rb +25 -3
- data/spec/api/group_checkin_list_spec.rb +2 -2
- data/spec/readers/api_reader_spec.rb +26 -0
- data/spec/spec_helper.rb +1 -2
- data/thecity_admin_api.gemspec +1 -15
- metadata +4 -2
data/lib/common.rb
CHANGED
@@ -26,7 +26,8 @@ module TheCity
|
|
26
26
|
begin
|
27
27
|
error_messages = JSON.parse(response.body)['error_message']
|
28
28
|
rescue
|
29
|
-
|
29
|
+
response_code_desc = response.headers.partition("\r\n")[0].sub(/^\S+/, '') rescue nil
|
30
|
+
raise TheCityExceptions::UnknownErrorConnectingToTheCity.new("Unknown error when connecting to The City.#{response_code_desc}")
|
30
31
|
else
|
31
32
|
raise TheCityExceptions::TheCityResponseError.new(error_messages)
|
32
33
|
end
|
data/lib/readers/api_reader.rb
CHANGED
@@ -2,6 +2,7 @@ module TheCity
|
|
2
2
|
|
3
3
|
# This adapter is the standard for all loading objects.
|
4
4
|
class ApiReader
|
5
|
+
attr_reader :headers
|
5
6
|
|
6
7
|
# Constructor
|
7
8
|
# def initialize
|
@@ -15,14 +16,35 @@ module TheCity
|
|
15
16
|
# data = @cacher.get_data( @class_key )
|
16
17
|
# else
|
17
18
|
@url_data_params ||= {}
|
18
|
-
response = TheCity::admin_request(:get, @url_data_path, @url_data_params)
|
19
|
-
data = JSON.parse(response.body)
|
20
|
-
@
|
19
|
+
response = TheCity::admin_request(:get, @url_data_path, @url_data_params)
|
20
|
+
data = JSON.parse(response.body)
|
21
|
+
@headers = parse_headers(response.headers) if response.headers
|
22
|
+
@cacher.save_data(@class_key, data) unless @cacher.nil?
|
21
23
|
#end
|
22
24
|
|
23
25
|
return data
|
24
26
|
end
|
25
27
|
|
28
|
+
def parse_headers(headers)
|
29
|
+
Hash[headers.split("\r\n").collect { |pair| pair.split(': ') }]
|
30
|
+
end
|
31
|
+
|
32
|
+
# Returns either the value of the X-City-RateLimit-Limit-By-Ip header or
|
33
|
+
# X-City-RateLimit-Limit-By-Account header, whichever is lower.
|
34
|
+
def rate_limit
|
35
|
+
if @headers
|
36
|
+
[@headers['X-City-RateLimit-Limit-By-Ip'].to_i, @headers['X-City-RateLimit-Limit-By-Account'].to_i].min
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Returns either the value of the X-City-RateLimit-Remaining-By-Ip header or
|
41
|
+
# X-City-RateLimit-Remaining-By-Account header, whichever is lower.
|
42
|
+
def rate_limit_remaining
|
43
|
+
if @headers
|
44
|
+
[@headers['X-City-RateLimit-Remaining-By-Ip'].to_i, @headers['X-City-RateLimit-Remaining-By-Account'].to_i].min
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
26
48
|
end
|
27
49
|
|
28
50
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
3
|
describe 'GroupCheckinList' do
|
4
4
|
|
@@ -11,7 +11,7 @@ describe 'GroupCheckinList' do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
|
14
|
-
it 'should pass if group checkin list attribute is not
|
14
|
+
it 'should pass if group checkin list attribute is not specified' do
|
15
15
|
group_id = 123
|
16
16
|
request_data = FactoryGirl.attributes_for(:group_checkin_list, {
|
17
17
|
:total_entries => 1,
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe TheCity::ApiReader do
|
4
|
+
|
5
|
+
it "should include City headers" do
|
6
|
+
headers = "X-City-RateLimit-Limit-By-Ip: 2200\r\nX-City-RateLimit-Remaining-By-Ip: 2199\r\n"
|
7
|
+
TheCity.stub(:admin_request).and_return(TheCityResponse.new(200, {}.to_json, headers))
|
8
|
+
reader = TheCity::ApiReader.new
|
9
|
+
reader.load_feed.should == {}
|
10
|
+
reader.headers['X-City-RateLimit-Limit-By-Ip'].should == '2200'
|
11
|
+
reader.headers['X-City-RateLimit-Remaining-By-Ip'].should == '2199'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should include convenience methods for reading rate limit data" do
|
15
|
+
headers = ["X-City-RateLimit-Limit-By-Ip: 2000",
|
16
|
+
"X-City-RateLimit-Remaining-By-Ip: 1987",
|
17
|
+
"X-City-RateLimit-Limit-By-Account: 3000",
|
18
|
+
"X-City-RateLimit-Remaining-By-Account: 1561"].join("\r\n")
|
19
|
+
TheCity.stub(:admin_request).and_return(TheCityResponse.new(200, {}.to_json, headers))
|
20
|
+
reader = TheCity::ApiReader.new
|
21
|
+
reader.load_feed.should == {}
|
22
|
+
reader.rate_limit.should == 2000
|
23
|
+
reader.rate_limit_remaining.should == 1561
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
#
|
4
4
|
# Author:: Wes Hays <weshays@gbdev.com>
|
5
5
|
# Link:: https://github.com/weshays/admin-api-ruby
|
6
|
-
# Version:: 0.1a
|
7
6
|
# Package:: TheCity::Admin
|
8
7
|
|
9
8
|
|
@@ -18,7 +17,7 @@ require 'factory_girl'
|
|
18
17
|
Dir.glob(File.dirname(__FILE__) + "/factories/*").each { |f| require f }
|
19
18
|
|
20
19
|
|
21
|
-
TheCityResponse = Struct.new(:code, :body)
|
20
|
+
TheCityResponse = Struct.new(:code, :body, :headers)
|
22
21
|
|
23
22
|
RSpec.configure do |config|
|
24
23
|
config.tty = true
|
data/thecity_admin_api.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
PROJECT_GEM = 'the-city-admin'
|
3
|
-
PROJECT_GEM_VERSION = '0.
|
3
|
+
PROJECT_GEM_VERSION = '0.3.0'
|
4
4
|
|
5
5
|
s.name = PROJECT_GEM
|
6
6
|
s.version = PROJECT_GEM_VERSION
|
@@ -23,17 +23,3 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
24
|
s.require_paths = ["lib"]
|
25
25
|
end
|
26
|
-
|
27
|
-
|
28
|
-
#s.require_path = 'lib/'
|
29
|
-
|
30
|
-
# s.files = ['LICENSE',
|
31
|
-
# 'README',
|
32
|
-
# 'lib/common_project_tasks.rb',
|
33
|
-
# 'lib/common_project_tasks/app.rake',
|
34
|
-
# 'examples/app_vars.yml']
|
35
|
-
|
36
|
-
# s.has_rdoc = true
|
37
|
-
# s.extra_rdoc_files = %w{README LICENSE}
|
38
|
-
# s.rdoc_options << '--title' << 'Common Project Tasks Documentation' <<
|
39
|
-
# '--main' << 'README' << '-q'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: the-city-admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: typhoeus
|
@@ -303,6 +303,7 @@ files:
|
|
303
303
|
- spec/factories/web_hook.rb
|
304
304
|
- spec/factories/web_hook_list.rb
|
305
305
|
- spec/functional/the_city_admin_spec.rb
|
306
|
+
- spec/readers/api_reader_spec.rb
|
306
307
|
- spec/readers/user_reader_spec.rb
|
307
308
|
- spec/spec_helper.rb
|
308
309
|
- spec/writers/skill_writer_spec.rb
|
@@ -435,6 +436,7 @@ test_files:
|
|
435
436
|
- spec/factories/web_hook.rb
|
436
437
|
- spec/factories/web_hook_list.rb
|
437
438
|
- spec/functional/the_city_admin_spec.rb
|
439
|
+
- spec/readers/api_reader_spec.rb
|
438
440
|
- spec/readers/user_reader_spec.rb
|
439
441
|
- spec/spec_helper.rb
|
440
442
|
- spec/writers/skill_writer_spec.rb
|