geekier_factory 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,52 @@
1
- geekier_factory_gem
2
- ===================
1
+ #Synopsis
3
2
 
4
- Ruby gem for using APIs, based on their Geekier API descriptions.
3
+ Ruby gem for using APIs, based on their Geekier API descriptions.
4
+
5
+ #Installation
6
+
7
+ ##Gemfile
8
+
9
+ `gem "geekier_factory"`
10
+
11
+ ##Standalone
12
+
13
+ `gem install geekier_factory`
14
+
15
+ #Usage
16
+
17
+ Download the API definition you want to use.
18
+
19
+ require 'geekier_factory'
20
+
21
+ # instanciate the api
22
+ api = GeekierFactory.factorize('path/to/definition_file.json')
23
+
24
+ # get a list of actions you can perform
25
+ api.available_actions
26
+
27
+ # select the action you want to perform
28
+ action = api.available_actions[3]
29
+
30
+ # check out what parameters are possible/necessary
31
+ action.params
32
+
33
+ # select an action and call it with its parameters
34
+ action.call(:param1 => 'valueA', :param2 => 'valueB)
35
+
36
+ And that's how you do it.
37
+
38
+ #Participate
39
+
40
+ * fork && commit && send\_pull\_request
41
+ * add [more API definitions](https://github.com/rulesio/geekier)
42
+ * join the [Geekier Google group](https://groups.google.com/d/forum/geekier-apis)
43
+
44
+ #TODO
45
+
46
+ (in no particular order)
47
+
48
+ * Implement support for resources
49
+ * Parameter validations
50
+ * Support for Authentication/API level configuration
51
+ * Add more descriptions
52
+ * Setup with all the cool testing and dependency checking solutions out there
@@ -67,13 +67,15 @@ module GeekierFactory
67
67
  Retry = Class.new(Exception)
68
68
  ConnectionException = Class.new(Exception)
69
69
  def handle_response!(response)
70
- if @structure['errorResponses'].map{ |er| er['code'] }.include? response.status
70
+ if (@structure['errorResponses'] + @api.error_responses).map{ |er| er['code'] }.include? response.status
71
71
  ex = @structure['errorResponses'].select{ |er| er['code'] == response.status }
72
- if ex['retry'] == true && (@retries ||= 0) < ex[ ]
72
+ if ex['retry'] == true && (@retries ||= 0) < ex['retry']
73
73
  @retries += 1
74
74
  raise Retry.new
75
75
  else
76
- raise ConnectionException.new("#{ex[:reason]} (HTTP status code #{ex[:code]})")
76
+ message = "#{ex[:reason]} (HTTP status code #{ex[:code]})"
77
+ message = message + "\n\n" + response[:body] if ex['details'] && ex['details'] == 'body'
78
+ raise ConnectionException.new(message)
77
79
  end
78
80
  elsif !response.success?
79
81
  raise ConnectionException.new
@@ -6,7 +6,7 @@ module GeekierFactory
6
6
  class API
7
7
  def initialize(structure)
8
8
  @structure = structure
9
- @actions = @structure['apis'].map{ |api| api['operations'].map{ |op| Action.new(self, op.merge('path' => api['path'])) } }.flatten
9
+ @actions = Hash[@structure['apis'].map{ |api| [api['description'], api['operations'].map{ |op| Action.new(self, op.merge('path' => api['path'])) }] }]
10
10
  end
11
11
 
12
12
  def log_body?
@@ -34,6 +34,10 @@ module GeekierFactory
34
34
  def base_url
35
35
  @structure['basePath'].end_with?('/') ? @structure['basePath'] : (@structure['basePath'] + '/')
36
36
  end
37
+
38
+ def error_responses
39
+ @structure['errorResponses'] || []
40
+ end
37
41
 
38
42
  # def oauth?
39
43
  # true
@@ -1,3 +1,3 @@
1
1
  module GeekierFactory
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -48,6 +48,8 @@
48
48
  "path": "/action.do"
49
49
  }
50
50
  ],
51
+ "errorResponses": [
52
+ ],
51
53
  "basePath": "http://localhost/api/v0.1",
52
54
  "resourcePath": "",
53
55
  "swaggerVersion": "1.1"
data/test/test_factory.rb CHANGED
@@ -6,7 +6,7 @@ class TestFactory < Test::Unit::TestCase
6
6
 
7
7
  setup do
8
8
  @api = GeekierFactory.factorize(File.join(File.dirname(File.expand_path(__FILE__)), 'mock_definition.json'))
9
- @action = @api.available_actions.first
9
+ @action = @api.available_actions["test api"].first
10
10
  end
11
11
 
12
12
  test "api should be factorized" do
@@ -14,8 +14,10 @@ class TestFactory < Test::Unit::TestCase
14
14
  assert @api.is_a? GeekierFactory::API
15
15
  end
16
16
 
17
- test "api should have one action" do
17
+ test "api should have one operation with action" do
18
18
  assert_equal 1, @api.available_actions.size
19
+ assert @api.available_actions.is_a? Hash
20
+ assert_equal 1, @api.available_actions["test api"].size
19
21
  end
20
22
 
21
23
  test "action should have 4 parameters" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geekier_factory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-28 00:00:00.000000000 Z
13
+ date: 2013-03-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -180,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
180
  version: 1.3.6
181
181
  requirements: []
182
182
  rubyforge_project:
183
- rubygems_version: 1.8.24
183
+ rubygems_version: 1.8.25
184
184
  signing_key:
185
185
  specification_version: 3
186
186
  summary: Generate API objects from swagger definition files