api_recipes 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NzBiNzgwZTQyYjI2MmU3NDk2Mzg3ZTA2ZmYzMWViM2E1YmRlN2RlNw==
4
+ YjgxODFjMzU4NzQwMjdkMWEyYTBlMmY1NWFjZTFkNmUwMTZhZDY5MQ==
5
5
  data.tar.gz: !binary |-
6
- N2Y1YTc4OTcxZGI3NWYxYWJmMDAxZWY4N2ViZTA3N2EyYzdhY2JmMA==
6
+ MzljOTgzNWUxNDYyOTZhYjljMGYzM2FkZWY5YzI0NjQwYTU2ZWI5OQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- M2VhNDJlZjYxMzQ3YjkxNDkyOGFlYTI0OGI5MTJjMjM1ZWJmMWU5MTg4M2Rl
10
- NjRlOWViOWVjNTk0NmRiZWYyMTA2MjAzNGFkYWU0YTc0YTgzNmUyNDE1NjA5
11
- N2ZkZTEzZTNjMDUxNTY1YTE3N2Y1YTUxYzdiNTc1NGRlMDU1ZWQ=
9
+ ZThhMzdmYTY0YWNmZDU3NDVmN2M4ZTQ1YzhkYTQ5MTA0MWU4OGY2ZGFlM2Nj
10
+ Y2JmN2Y3MmIwNDM2YjY3MTc0NWEyYzc1ODVlZWYzNDk4NDI5YmI5OGIxOTRm
11
+ ZmIzYmViNWI1YzU4MjA1YmZkMjE5NzFlYmJiMjQxY2EzMGM5MjU=
12
12
  data.tar.gz: !binary |-
13
- NzQxMWY0NGI3NzQzMzBlZDFjNWM0MjE0M2ZkNzQ1NTdjMGU5YmI2NTAzYWZi
14
- ZTUzNjk5NDBiYzQ4ZjQ4MGY0ZWEzYzAxZjFkZGVjMmM1ZTVlZWM1NjljNjJj
15
- NTQ0Nzg3MWU0OWU5MDE4M2UyMzAxNzY5NDk0MjY4ZjY3MGFhZDc=
13
+ Mjc0Y2MyNzFkNTY4Y2FjZjJmNWIwOTNjYmI0MmNmMWNhN2E0NjY3ZDUwNzU1
14
+ YjRhZmZmNjExZTZkNzg0N2Y0NzdkZjVjMzhhMGJkNzUzNGY0OWFkNDlmMDlk
15
+ YTg4ZTNlMGM5Zjg3MmRhZmM1YTE4NTgwMTI5NDExOTc3NDM2MmM=
data/README.md CHANGED
@@ -2,7 +2,13 @@
2
2
 
3
3
  # ApiRecipes
4
4
 
5
- Consume HTTP APIs with style
5
+ <p align="center">
6
+ <img width="300" height="160" src="api_recipes.png"/>
7
+ </p>
8
+
9
+ Create your HTTP APIs recipes and tastefully consume it!
10
+
11
+ Api recipes lets you easily describe and consume an HTTP API.
6
12
 
7
13
  ## Installation
8
14
 
@@ -26,26 +32,18 @@ Ruby 1.9.3 or higher.
26
32
 
27
33
  ## Usage
28
34
 
29
- ... in progress.
35
+ Help needed.
30
36
 
31
37
  In the meantime take a look at the ``` examples ``` folder. Thank you.
32
38
 
33
39
  ## TODO
34
40
 
35
- * Write specs
41
+ * Write specs (I know... this code has been wrote down on a hurry so please do not beat me)
36
42
  * Write a good Usage
37
43
  * Add more examples
44
+ * Add documentation
38
45
  * Delete this TODO section
39
46
 
40
- ## Development
41
-
42
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
43
- You can also run `bin/console` for an interactive prompt that will allow you to experiment.
44
-
45
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update
46
- the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for
47
- the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
48
-
49
47
  ## Contributing
50
48
 
51
49
  Bug reports and pull requests are welcome on GitHub at https://github.com/madAle/api_recipes.
data/api_recipes.png ADDED
Binary file
@@ -62,6 +62,21 @@ module ApiRecipes
62
62
  end
63
63
  end
64
64
 
65
+ def encode_residual_params(route_attributes, residual_params)
66
+ # If :encode_params_as is specified and avalable use it
67
+ if Settings::AVAILABLE_PARAMS_ENCODINGS.include? route_attributes[:encode_params_as].to_s
68
+ { route_attributes[:encode_params_as].to_sym => residual_params }
69
+ else
70
+ # default to query string params (get) or json (other methods)
71
+ case route_attributes[:method].to_sym
72
+ when :get
73
+ { params: residual_params }
74
+ when :post, :put, :patch, :delete
75
+ { json: residual_params }
76
+ end
77
+ end
78
+ end
79
+
65
80
  def extract_headers
66
81
  settings[:default_headers] || {}
67
82
  end
@@ -70,6 +85,9 @@ module ApiRecipes
70
85
  # e.g. webapp.alarms.index
71
86
  def generate_routes
72
87
  @routes.each do |route, attrs|
88
+ if attrs.is_a? Hash
89
+ attrs.deep_symbolize_keys!
90
+ end
73
91
  if route.eql? @name
74
92
  raise RouteNameClashError.new(route, @name)
75
93
  end
@@ -90,11 +108,11 @@ module ApiRecipes
90
108
 
91
109
  def port
92
110
  settings[:port] || case settings[:protocol]
93
- when 'http'
94
- 80
95
- when 'https'
96
- 443
97
- end
111
+ when 'http'
112
+ 80
113
+ when 'https'
114
+ 443
115
+ end
98
116
  end
99
117
 
100
118
  def request
@@ -128,16 +146,15 @@ module ApiRecipes
128
146
  unless route_attributes
129
147
  route_attributes = {}
130
148
  end
131
- unless method = route_attributes[:method]
132
- method = Settings::DEFAULT_HTTP_VERB
133
- end
149
+ # Merge route attributes with defaults
150
+ route_attributes = Settings::DEFAULT_ROUTE_ATTRIBUTES.merge route_attributes
134
151
 
135
152
  params = pars.extract_options!
136
153
  path, residual_params = build_path(route, route_attributes, params)
137
154
  residual_params = nil unless residual_params.any?
138
155
  uri = build_uri_from path
139
156
 
140
- response = build_request.send(method.downcase, uri, json: residual_params)
157
+ response = build_request.send(route_attributes[:method], uri, encode_residual_params(route_attributes, residual_params))
141
158
  check_response_code route, route_attributes, response
142
159
 
143
160
  if block_given?
@@ -14,6 +14,10 @@ module ApiRecipes
14
14
  routes: {}
15
15
  }
16
16
 
17
- DEFAULT_HTTP_VERB = :get
17
+ DEFAULT_ROUTE_ATTRIBUTES = {
18
+ method: :get
19
+ }
20
+
21
+ AVAILABLE_PARAMS_ENCODINGS = %w(form params json body)
18
22
  end
19
23
  end
@@ -1,3 +1,3 @@
1
1
  module ApiRecipes
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_recipes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Verlato
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-18 00:00:00.000000000 Z
11
+ date: 2015-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -83,6 +83,7 @@ files:
83
83
  - README.md
84
84
  - Rakefile
85
85
  - api_recipes.gemspec
86
+ - api_recipes.png
86
87
  - bin/console
87
88
  - bin/setup
88
89
  - examples/authorization.rb