datacatalog 0.1.0 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datacatalog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luigi Montanez
@@ -10,9 +10,49 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-10-05 00:00:00 -04:00
13
+ date: 2009-10-09 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: activesupport
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 2.3.4
25
+ version:
26
+ - !ruby/object:Gem::Dependency
27
+ name: httparty
28
+ type: :runtime
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 0.4.5
35
+ version:
36
+ - !ruby/object:Gem::Dependency
37
+ name: mash
38
+ type: :runtime
39
+ version_requirement:
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 0.0.3
45
+ version:
46
+ - !ruby/object:Gem::Dependency
47
+ name: jeweler
48
+ type: :development
49
+ version_requirement:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.2.1
55
+ version:
16
56
  - !ruby/object:Gem::Dependency
17
57
  name: rspec
18
58
  type: :development
@@ -21,7 +61,7 @@ dependencies:
21
61
  requirements:
22
62
  - - ">="
23
63
  - !ruby/object:Gem::Version
24
- version: "0"
64
+ version: 1.2.8
25
65
  version:
26
66
  description: Ruby library that wraps the National Data Catalog API
27
67
  email: luigi@sunlightfoundation.com
@@ -40,17 +80,18 @@ files:
40
80
  - Rakefile
41
81
  - VERSION
42
82
  - datacatalog.gemspec
43
- - doc/api_key_spec_for_rest_api.txt
44
- - doc/api_key_spec_for_ruby_api.rb
45
- - doc/mocking_options.md
83
+ - lib/base.rb
46
84
  - lib/datacatalog.rb
47
- - lib/datacatalog/api_key.rb
48
- - lib/datacatalog/base.rb
49
- - lib/datacatalog/source.rb
50
- - lib/datacatalog/user.rb
85
+ - lib/main.rb
86
+ - lib/resources/about.rb
87
+ - lib/resources/api_key.rb
88
+ - lib/resources/source.rb
89
+ - lib/resources/user.rb
51
90
  - sandbox_api.yml.example
91
+ - spec/about_spec.rb
52
92
  - spec/api_key_spec.rb
53
93
  - spec/base_spec.rb
94
+ - spec/datacatalog_spec.rb
54
95
  - spec/source_spec.rb
55
96
  - spec/spec.opts
56
97
  - spec/spec_helper.rb
@@ -78,14 +119,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
119
  version:
79
120
  requirements: []
80
121
 
81
- rubyforge_project:
122
+ rubyforge_project: datacatalog
82
123
  rubygems_version: 1.3.5
83
124
  signing_key:
84
125
  specification_version: 3
85
126
  summary: Wrapper for the National Data Catalog API
86
127
  test_files:
128
+ - spec/about_spec.rb
87
129
  - spec/api_key_spec.rb
88
130
  - spec/base_spec.rb
131
+ - spec/datacatalog_spec.rb
89
132
  - spec/source_spec.rb
90
133
  - spec/spec_helper.rb
91
134
  - spec/user_spec.rb
@@ -1,54 +0,0 @@
1
- A user has a built-in, primary API key.
2
- A user also has secondary API keys.
3
-
4
- API keys fall into these categories:
5
- 1. "primary" API key
6
- - created and controlled by system
7
- - cannot be deleted by users
8
- - used by the Data Catalog Web Application
9
- - can be rekeyed by user
10
- 2. application keys
11
- - created and controlled by users
12
- - can be rekeyed by user
13
- - do not provide user-specific credentials:
14
- - favorites
15
- - comments
16
- 3. valet keys
17
- - created and controlled by users
18
- - can be rekeyed by user
19
- - provide user-specific credentials
20
- - favorites
21
- - comments
22
-
23
- GET /users/1/api_keys
24
- # get all API keys
25
- :type => :primary
26
- :type => :application
27
- :type => :valet
28
-
29
- GET /users/1/api_keys?type=primary
30
- # just returns the primary key
31
-
32
- GET /users/1/api_keys?type=application
33
- # returns an array of application keys. [] if none.
34
-
35
- GET /users/1/api_keys?type=valet
36
- # returns an array of the valet keys. [] if none.
37
-
38
- POST /users/1/api_keys
39
- # create a new API key
40
-
41
- PUT /users/1/api_keys/12345
42
- # update an existing API key
43
-
44
- PUT /users/1/api_keys/12345?regenerate_api_key=true
45
- # rekey an API key
46
-
47
- DELETE /users/1/api_keys/12345
48
- # delete an existing API key
49
- # return 403 Forbidden if attempting to delete a primary key
50
-
51
- # -----
52
-
53
- POST /users
54
- A a primary key API should be generated automatically.
@@ -1,26 +0,0 @@
1
- # I want to get a user's primary API key
2
- user = DataCatalog::User.find(user_id)
3
- user.primary_api_key
4
- user.application_api_keys
5
- user.valet_api_keys
6
-
7
- # I want to generate a new API key for a user
8
- user.generate_api_key!(:type => "application", :purpose => "To be awesome.") # sets user to the updated object
9
-
10
- # I want to update an API key
11
- user.update_api_key!("173f938237a93e9393b365c3",
12
- :type => "application",
13
- :purpose => "To be more awesome.") # sets user to the updated object
14
-
15
- # I want to delete an API key of a user
16
- user.delete_api_key!("173f938237a93e9393b365c3") # returns: true / exception
17
-
18
- # I want to get all API keys of a single user
19
- user.api_keys # returns: array of keys
20
-
21
- # ^^^^^^^^^^^^ DONE ^^^^^^^^^^^^^^^
22
-
23
- # vvvvvvvvvv NOT DONE vvvvvvvvvvvvv
24
-
25
- # Given an API key, I want to see what user it corresponds to, if any.
26
- DataCatalog::User.find_by_api_key("7a93e93b365ca93e9393b365c3") # returns: User object
@@ -1,20 +0,0 @@
1
- # Ruby wrapper API mocking options
2
-
3
- ## 1. Machinist
4
-
5
- * Use Machinist as an object factory for HTTParty::Response and DataCatalog::* objects.
6
- * Big question: Can HTTParty::Response object methods be appropriately mocked out by Machinist?
7
- * Will need to keep objects in sync with the live API
8
-
9
- ## 2. FakeWeb
10
-
11
- * Use FakeWeb to fake out the HTTP responses
12
- * Will need to know the details of the JSON bodies, but HTTParty wraps all that for us.
13
- * Will need to keep the JSON output (and headers + status codes) in sync with the live API
14
-
15
- ## 3. Local Sandbox API
16
-
17
- * Use a locally running sandbox API that mocks out the real API
18
- * Each spec will need to build up needed objects in the API, then tear them down at the end.
19
- * Much slower than in-memory solutions above.
20
- * To keep in sync with live API, just need to refresh API codebase.
@@ -1,7 +0,0 @@
1
- module DataCatalog
2
-
3
- class ApiKey < DataCatalog::Base
4
-
5
- end # class ApiKey
6
-
7
- end # module DataCatalog
@@ -1,68 +0,0 @@
1
- module DataCatalog
2
-
3
- class Base < Mash
4
-
5
- include HTTParty
6
- format :json
7
-
8
- def self.set_base_uri
9
- default_options[:base_uri] = HTTParty.normalize_base_uri(DataCatalog.base_uri || 'api.nationaldatacatalog.com')
10
- end
11
-
12
- def self.set_api_key
13
- if DataCatalog.api_key.blank?
14
- raise ApiKeyNotConfigured, "Use DataCatalog.api_key = '...'"
15
- end
16
- default_options[:default_params] = {} if default_options[:default_params].nil?
17
- default_options[:default_params].merge!({ :api_key => DataCatalog.api_key })
18
- end
19
-
20
- def self.set_up!
21
- set_base_uri
22
- set_api_key
23
- end
24
-
25
- def self.check_status_code(response)
26
- case response.code
27
- when 400: raise BadRequest, error_message(response)
28
- when 401: raise Unauthorized, error_message(response)
29
- when 403: raise Forbidden, error_message(response)
30
- when 404: raise NotFound, error_message(response)
31
- when 409: raise Conflict, error_message(response)
32
- when 500: raise InternalServerError, error_message(response)
33
- end
34
- end
35
-
36
- def self.error_message(response)
37
- parsed_body = JSON.parse(response.body)
38
- if parsed_body.empty?
39
- "Response was empty"
40
- elsif parsed_body["errors"]
41
- parsed_body["errors"].inspect
42
- else
43
- response.body
44
- end
45
- rescue JSON::ParserError
46
- "Unable to parse: #{response.body.inspect}"
47
- end
48
-
49
- def self.response_for
50
- response = yield
51
- check_status_code(response)
52
- response
53
- end
54
-
55
- def self.build_object(response)
56
- return nil if response.nil? || response.empty?
57
- new(response)
58
- end
59
-
60
- def self.about
61
- default_options[:default_params] = {}
62
- set_base_uri
63
- build_object(response_for { get('/') })
64
- end
65
-
66
- end # class Base
67
-
68
- end # module DataCatalog
@@ -1,30 +0,0 @@
1
- module DataCatalog
2
-
3
- class Source < DataCatalog::Base
4
-
5
- def self.create(params={})
6
- set_up!
7
- build_object(response_for { post("/sources", :query => params) })
8
- end
9
-
10
- def self.all
11
- set_up!
12
- response_for{ get("/sources") }.map do |source|
13
- build_object(source)
14
- end
15
- end
16
-
17
- def self.update(source_id, params={})
18
- set_up!
19
- build_object(response_for { put("/sources/#{source_id}", :query => params) })
20
- end
21
-
22
- def self.destroy(source_id)
23
- set_up!
24
- response = response_for { delete("/sources/#{source_id}") }
25
- true
26
- end
27
-
28
- end
29
-
30
- end
@@ -1,94 +0,0 @@
1
- module DataCatalog
2
-
3
- class User < DataCatalog::Base
4
-
5
- def self.all
6
- set_up!
7
- response_for{ get("/users") }.map do |user|
8
- build_object(user)
9
- end
10
- end
11
-
12
- def self.find(id)
13
- set_up!
14
- user = build_object(response_for { get("/users/#{id}") })
15
- user.api_keys = response_for { get("/users/#{id}/keys") }.map do |key|
16
- DataCatalog::ApiKey.build_object(key)
17
- end if user
18
- user
19
- end
20
-
21
- def self.find_by_api_key(api_key)
22
- user = nil
23
- DataCatalog.with_key(api_key) do
24
- set_up!
25
- checkup = build_object(response_for { get("/checkup") })
26
- user = find(checkup.user_id)
27
- end
28
- user
29
- end
30
-
31
- def self.create(params={})
32
- set_up!
33
- user = build_object(response_for { post("/users", :query => params) })
34
- user.api_keys = response_for { get("/users/#{user.id}/keys") }.map do |key|
35
- DataCatalog::ApiKey.build_object(key)
36
- end if user
37
- user
38
- end
39
-
40
- def self.update(user_id, params)
41
- set_up!
42
- build_object(response_for { put("/users/#{user_id}", :query => params) })
43
- end
44
-
45
- def self.destroy(user_id)
46
- set_up!
47
- response = response_for { delete("/users/#{user_id}") }
48
- true
49
- end
50
-
51
- def generate_api_key!(params)
52
- self.class.set_up!
53
-
54
- response = self.class.response_for do
55
- self.class.post("/users/#{self.id}/keys", :query => params )
56
- end
57
- update_api_keys
58
- true
59
- end
60
-
61
- def delete_api_key!(api_key_id)
62
- self.class.set_up!
63
-
64
- response = self.class.response_for do
65
- self.class.delete("/users/#{self.id}/keys/#{api_key_id}")
66
- end
67
- update_api_keys
68
- true
69
- end
70
-
71
- def update_api_key!(api_key_id, params)
72
- self.class.set_up!
73
-
74
- response = self.class.response_for do
75
- self.class.put("/users/#{self.id}/keys/#{api_key_id}", :query => params)
76
- end
77
- update_api_keys
78
- true
79
- end
80
-
81
- private
82
-
83
- def update_api_keys
84
- self.api_keys = self.class.response_for { self.class.get("/users/#{self.id}/keys") }.map do |key|
85
- DataCatalog::ApiKey.build_object(key)
86
- end
87
- updated_user = DataCatalog::User.find(self.id)
88
- self.application_api_keys = updated_user.application_api_keys
89
- self.valet_api_keys = updated_user.valet_api_keys
90
- end
91
-
92
- end # class User
93
-
94
- end # module DataCatalog