edamam-ruby 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 14ba1994d75dba6f5c62d670772a669ff81a3a53
4
+ data.tar.gz: 73367fef388135111120c6db0ba31f9b2a8bc47c
5
+ SHA512:
6
+ metadata.gz: 655644b8a476ad152e5295577db17ee1bd2d93937b7e103cf295736a2c0f8251f128a4b5667ab29675f5200c31bc861dceef565537c3b2ee6831dc31bf2dc44d
7
+ data.tar.gz: ba911129de38f782f5070e43e45627a9325c69b33c4b739ea3c2cfcae4ac7707abb5918e9b3d0d9b850f85a4b750189b705eea308398e1da69cb0306abee3940
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.hound.yml ADDED
@@ -0,0 +1,4 @@
1
+ fail_on_violations: true
2
+ ruby:
3
+ config_file: .rubocop.yml
4
+
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,394 @@
1
+ AllCops:
2
+ Include:
3
+ - '**/Rakefile'
4
+ - '**/config.ru'
5
+ Exclude:
6
+ - 'db/**/*'
7
+ - 'config/**/*'
8
+ - 'script/**/*'
9
+
10
+ AccessorMethodName:
11
+ Enabled: false
12
+
13
+ ActionFilter:
14
+ Enabled: false
15
+
16
+ Alias:
17
+ Enabled: false
18
+
19
+ ArrayJoin:
20
+ Enabled: false
21
+
22
+ AsciiComments:
23
+ Enabled: false
24
+
25
+ AsciiIdentifiers:
26
+ Enabled: false
27
+
28
+ Attr:
29
+ Enabled: false
30
+
31
+ BlockNesting:
32
+ Enabled: false
33
+
34
+ CaseEquality:
35
+ Enabled: false
36
+
37
+ CharacterLiteral:
38
+ Enabled: false
39
+
40
+ ClassAndModuleChildren:
41
+ Enabled: false
42
+
43
+ ClassLength:
44
+ Enabled: false
45
+
46
+ ModuleLength:
47
+ Enabled: false
48
+
49
+ ClassVars:
50
+ Enabled: false
51
+
52
+ CollectionMethods:
53
+ Enabled: true
54
+ PreferredMethods:
55
+ find: detect
56
+ inject: reduce
57
+ collect: map
58
+ find_all: select
59
+
60
+ ColonMethodCall:
61
+ Enabled: false
62
+
63
+ CommentAnnotation:
64
+ Enabled: false
65
+
66
+ CyclomaticComplexity:
67
+ Enabled: false
68
+
69
+ Delegate:
70
+ Enabled: false
71
+
72
+ PreferredHashMethods:
73
+ Enabled: false
74
+
75
+ Documentation:
76
+ Enabled: false
77
+
78
+ DotPosition:
79
+ EnforcedStyle: trailing
80
+
81
+ DoubleNegation:
82
+ Enabled: false
83
+
84
+ EachWithObject:
85
+ Enabled: false
86
+
87
+ EmptyLiteral:
88
+ Enabled: false
89
+
90
+ EmptyLinesAroundAccessModifier:
91
+ Description: "Keep blank lines around access modifiers."
92
+ Enabled: true
93
+
94
+ EmptyLinesAroundBlockBody:
95
+ Enabled: false
96
+
97
+ EmptyLinesAroundClassBody:
98
+ Enabled: false
99
+
100
+ EmptyLinesAroundModuleBody:
101
+ Enabled: false
102
+
103
+ EmptyLinesAroundMethodBody:
104
+ Enabled: false
105
+
106
+ Encoding:
107
+ Enabled: false
108
+
109
+ EvenOdd:
110
+ Enabled: false
111
+
112
+ ExtraSpacing:
113
+ Enabled: true
114
+
115
+ FileName:
116
+ Enabled: false
117
+
118
+ FlipFlop:
119
+ Enabled: false
120
+
121
+ FormatString:
122
+ Enabled: false
123
+
124
+ FrozenStringLiteralComment:
125
+ Enabled: false
126
+
127
+ GlobalVars:
128
+ Enabled: false
129
+
130
+ GuardClause:
131
+ Enabled: false
132
+
133
+ IfUnlessModifier:
134
+ Enabled: false
135
+
136
+ IfWithSemicolon:
137
+ Enabled: false
138
+
139
+ InlineComment:
140
+ Enabled: false
141
+
142
+ Lambda:
143
+ Enabled: false
144
+
145
+ LambdaCall:
146
+ Enabled: false
147
+
148
+ LineEndConcatenation:
149
+ Enabled: false
150
+
151
+ LineLength:
152
+ Max: 80
153
+
154
+ MethodLength:
155
+ Enabled: false
156
+
157
+ ModuleFunction:
158
+ Enabled: false
159
+
160
+ MultilineOperationIndentation:
161
+ Enabled: true
162
+ EnforcedStyle: indented
163
+
164
+ NegatedIf:
165
+ Enabled: false
166
+
167
+ NegatedWhile:
168
+ Enabled: false
169
+
170
+ Next:
171
+ Enabled: false
172
+
173
+ NilComparison:
174
+ Enabled: false
175
+
176
+ Not:
177
+ Enabled: false
178
+
179
+ NumericLiterals:
180
+ Enabled: false
181
+
182
+ OneLineConditional:
183
+ Enabled: false
184
+
185
+ OpMethod:
186
+ Enabled: false
187
+
188
+ ParameterLists:
189
+ Enabled: false
190
+
191
+ PercentLiteralDelimiters:
192
+ Enabled: false
193
+
194
+ PerlBackrefs:
195
+ Enabled: false
196
+
197
+ PredicateName:
198
+ NamePrefixBlacklist:
199
+ - is_
200
+ Exclude:
201
+ - spec/**/*
202
+
203
+ Proc:
204
+ Enabled: false
205
+
206
+ RaiseArgs:
207
+ Enabled: false
208
+
209
+ RegexpLiteral:
210
+ Enabled: false
211
+
212
+ SelfAssignment:
213
+ Enabled: false
214
+
215
+ SingleLineBlockParams:
216
+ Enabled: false
217
+
218
+ SingleLineMethods:
219
+ Enabled: false
220
+
221
+ SignalException:
222
+ Enabled: false
223
+
224
+ SpecialGlobalVars:
225
+ Enabled: false
226
+
227
+ StringLiterals:
228
+ EnforcedStyle: double_quotes
229
+
230
+ TrailingCommaInArguments:
231
+ EnforcedStyleForMultiline: no_comma
232
+ SupportedStyles:
233
+ - comma
234
+ - consistent_comma
235
+ - no_comma
236
+
237
+ TrailingCommaInLiteral:
238
+ EnforcedStyleForMultiline: comma
239
+ SupportedStyles:
240
+ - comma
241
+ - consistent_comma
242
+ - no_comma
243
+
244
+ TrailingBlankLines:
245
+ Enabled: false
246
+
247
+ TrivialAccessors:
248
+ Enabled: false
249
+
250
+ VariableInterpolation:
251
+ Enabled: false
252
+
253
+ WhenThen:
254
+ Enabled: false
255
+
256
+ WhileUntilModifier:
257
+ Enabled: false
258
+
259
+ WordArray:
260
+ Enabled: false
261
+
262
+ # Lint
263
+
264
+ AmbiguousOperator:
265
+ Enabled: false
266
+
267
+ AmbiguousRegexpLiteral:
268
+ Enabled: false
269
+
270
+ AssignmentInCondition:
271
+ Enabled: false
272
+
273
+ CircularArgumentReference:
274
+ Enabled: false
275
+
276
+ ConditionPosition:
277
+ Enabled: false
278
+
279
+ DeprecatedClassMethods:
280
+ Enabled: false
281
+
282
+ DuplicatedKey:
283
+ Enabled: false
284
+
285
+ EachWithObjectArgument:
286
+ Enabled: false
287
+
288
+ ElseLayout:
289
+ Enabled: false
290
+
291
+ FormatParameterMismatch:
292
+ Enabled: false
293
+
294
+ HandleExceptions:
295
+ Enabled: false
296
+
297
+ InvalidCharacterLiteral:
298
+ Enabled: false
299
+
300
+ InitialIndentation:
301
+ Enabled: false
302
+
303
+ LiteralInCondition:
304
+ Enabled: false
305
+
306
+ LiteralInInterpolation:
307
+ Enabled: false
308
+
309
+ Loop:
310
+ Enabled: false
311
+
312
+ NestedMethodDefinition:
313
+ Enabled: false
314
+
315
+ NonLocalExitFromIterator:
316
+ Enabled: false
317
+
318
+ ParenthesesAsGroupedExpression:
319
+ Enabled: false
320
+
321
+ RequireParentheses:
322
+ Enabled: false
323
+
324
+ UnderscorePrefixedVariableName:
325
+ Enabled: false
326
+
327
+ UnneededDisable:
328
+ Enabled: false
329
+
330
+ Void:
331
+ Enabled: false
332
+
333
+ # Performance
334
+
335
+ CaseWhenSplat:
336
+ Enabled: false
337
+
338
+ Count:
339
+ Enabled: false
340
+
341
+ Detect:
342
+ Enabled: false
343
+
344
+ FlatMap:
345
+ Enabled: false
346
+
347
+ ReverseEach:
348
+ Enabled: false
349
+
350
+ Sample:
351
+ Enabled: false
352
+
353
+ Size:
354
+ Enabled: false
355
+
356
+ StringReplacement:
357
+ Enabled: false
358
+
359
+ # Rails
360
+
361
+ ActionFilter:
362
+ Enabled: false
363
+
364
+ Date:
365
+ Enabled: false
366
+
367
+ FindBy:
368
+ Enabled: false
369
+
370
+ FindEach:
371
+ Enabled: false
372
+
373
+ HasAndBelongsToMany:
374
+ Enabled: false
375
+
376
+ Output:
377
+ Enabled: false
378
+
379
+ ReadWriteAttribute:
380
+ Enabled: false
381
+
382
+ ScopeArgs:
383
+ Enabled: false
384
+
385
+ TimeZone:
386
+ Enabled: false
387
+
388
+ Validation:
389
+ Enabled: false
390
+
391
+ Style/MultilineBlockChain:
392
+ Description: 'Avoid multi-line chains of blocks.'
393
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#single-line-blocks'
394
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at olalekan.eyiowuawi@andela.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in edamam_ruby.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 Gobble Development
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Edamam-ruby
2
+
3
+ This is a ruby wrapper for the [Edamam api](https://developer.edamam.com/edamam-docs-nutrition-api).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'edamam-ruby'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install edamam-ruby
20
+
21
+ ## Usage
22
+ To use this library you have to initialize the Edamam::Client with a valid app_id and app_key. If you dont have one, you can register with Edamam and get your credentials.
23
+ ```
24
+ client = Edamam::Client.new(app_id: "secret-app-id", app_key: "super-secret-app_id")
25
+ ```
26
+ Or you can instantiate with a block
27
+ ```
28
+ client = Edamam::Client.new do |client|
29
+ client.app_id = "secret-app-id"
30
+ client.app_key = "super-secret-app_id"
31
+ end
32
+ ```
33
+
34
+ After instantiating, you can make a request to the Edamam foodrequest api
35
+ ```
36
+ nutritional_data = client.food_database.nutritional_data("1 large apple")
37
+ ```
38
+ This would return an object which has all the successfull fields from [Edamam api](https://developer.edamam.com/edamam-docs-nutrition-api).
39
+
40
+ ###Note
41
+ This gem makes use of a logger in case there is an error. You can customize this logger to use any logger of your choice.
42
+ For example, in a rails application you can simple add this as an initializer
43
+ ```
44
+ Edamam.logger = Rails.logger
45
+ ```
46
+ ## Development
47
+
48
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
49
+
50
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/gobble/edamam-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "edamam-ruby"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'edamam-ruby/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "edamam-ruby"
8
+ spec.version = Edamam::VERSION
9
+ spec.authors = ["Olalekan Eyiowuawi", "Chris Woodford", "Mayowa Pitan"]
10
+ spec.email = ["olalekan.eyiowuawi@andela.com", "chris@gobble.com", "mayowa.pitan@andela.com"]
11
+
12
+ spec.summary = %q{This a ruby wrapper for the Edamam Nutrition api}
13
+ spec.description = %q{This a ruby wrapper for the Edamam Nutrition api}
14
+ spec.homepage = "https://github.com/gobble/edamam-ruby"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.13"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ spec.add_development_dependency "pry"
36
+ spec.add_development_dependency "webmock"
37
+ end
@@ -0,0 +1,9 @@
1
+ module Edamam
2
+ module Utils
3
+ module Api
4
+ BASE_URL = "https://api.edamam.com".freeze
5
+
6
+ FOOD_DATABASE_URL = "/api/nutrition-data".freeze
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,73 @@
1
+ module Edamam
2
+ module Utils
3
+ class Connection
4
+
5
+ VERB_MAP = {
6
+ get: Net::HTTP::Get,
7
+ post: Net::HTTP::Post,
8
+ }.freeze
9
+
10
+ ERROR_MAP = {
11
+ "401" => [UnauthorizedError, "Invalid App Id or App key"],
12
+ "422" => [
13
+ UnprocessableEntityError,
14
+ "Couldn’t parse the recipe or extract the nutritional info",
15
+ ],
16
+ "555" => [
17
+ InsufficientQualityError,
18
+ "Recipe with insufficient quality to process correctly",
19
+ ],
20
+ }.freeze
21
+
22
+ def initialize
23
+ uri = URI.parse(Utils::Api::BASE_URL)
24
+ @http = Net::HTTP.new(uri.host, uri.port)
25
+ @http.use_ssl = true
26
+ end
27
+
28
+ VERB_MAP.keys.each do |method_name|
29
+ define_method(method_name) do |path, params, header = {}|
30
+ status_code, body = process_request(method_name, path, params, header)
31
+ OpenStruct.new(body.merge(code: status_code)) if status_code
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def process_request(method, path, params, header)
38
+ response = make_request(method, path, params, header)
39
+ raise_error_or_parse_body(response.code, response.body)
40
+ rescue Timeout::Error, SocketError, TypeError => e
41
+ Edamam.log.error e.message
42
+ nil
43
+ end
44
+
45
+ def raise_error_or_parse_body(code, body)
46
+ raise ERROR_MAP[code][0], ERROR_MAP[code][1] unless code == "200"
47
+ [code, JSON.parse(body)]
48
+ end
49
+
50
+ def make_request(method, path, params = {}, headers = {})
51
+ path = method == :get ? encode_path_params(path, params) : path
52
+ request = VERB_MAP[method.to_sym].new(path)
53
+ request.set_form_data(params) if method == :post
54
+ set_headers(headers)
55
+ @http.request(request)
56
+ end
57
+
58
+ def encode_path_params(path, params)
59
+ encoded_path = URI.encode_www_form(params)
60
+ unescaped_encoded_path = [path, encoded_path].join("?").tr("+", " ")
61
+ URI.escape(unescaped_encoded_path)
62
+ end
63
+
64
+ def set_headers(headers)
65
+ unless headers.empty?
66
+ headers.each do |key, value|
67
+ request.add_field(key.to_s, value)
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,15 @@
1
+ module Edamam
2
+ module Utils
3
+ class MissingKeyError < StandardError
4
+ end
5
+
6
+ class UnauthorizedError < StandardError
7
+ end
8
+
9
+ class UnprocessableEntityError < StandardError
10
+ end
11
+
12
+ class InsufficientQualityError < StandardError
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ module Edamam
2
+ class Client
3
+ attr_accessor :app_key, :app_id, :food_database
4
+ def initialize(**args)
5
+ args.each_pair do |attribute, value|
6
+ instance_variable_set("@#{attribute}", value)
7
+ end
8
+ yield self if block_given?
9
+ raise_error_if_keys_not_present unless app_key && app_id
10
+ @food_database = FoodDatabase.new(self)
11
+ end
12
+
13
+ private
14
+
15
+ def raise_error_if_keys_not_present
16
+ raise Utils::MissingKeyError, "Missing Api key or App Id"
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,16 @@
1
+ module Edamam
2
+ class FoodDatabase
3
+ attr_reader :client
4
+ def initialize(client)
5
+ @client = client
6
+ end
7
+
8
+ def nutritional_data(ingredient)
9
+ connection = Utils::Connection.new
10
+ connection.get(
11
+ Utils::Api::FOOD_DATABASE_URL,
12
+ app_id: client.app_id, app_key: client.app_key, ingr: ingredient
13
+ )
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Edamam
2
+ VERSION = "0.1.1".freeze
3
+ end
@@ -0,0 +1,33 @@
1
+ require "net/http"
2
+ require "uri"
3
+ require "ostruct"
4
+ require "json"
5
+ require "logger"
6
+ require_relative "./edamam-ruby/version"
7
+ require_relative "./edamam-ruby/utils/errors"
8
+ require_relative "./edamam-ruby/utils/api"
9
+ require_relative "./edamam-ruby/utils/connection"
10
+ require_relative "./edamam-ruby/food_database"
11
+ require_relative "./edamam-ruby/client"
12
+
13
+ module Edamam
14
+ class << self
15
+ def logger=(logger)
16
+ @logger = logger
17
+ end
18
+
19
+ def log
20
+ @logger ||= initialize_logger
21
+ end
22
+
23
+ private
24
+
25
+ def initialize_logger
26
+ logger = Logger.new(STDERR)
27
+ logger.level = Logger::DEBUG
28
+ logger.datetime_format = "%Y-%m-%d %H:%M:%S "
29
+ logger
30
+ end
31
+ end
32
+
33
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: edamam-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Olalekan Eyiowuawi
8
+ - Chris Woodford
9
+ - Mayowa Pitan
10
+ autorequire:
11
+ bindir: exe
12
+ cert_chain: []
13
+ date: 2017-03-01 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.13'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '1.13'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rake
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '10.0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '10.0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rspec
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '3.0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '3.0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: pry
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: webmock
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ description: This a ruby wrapper for the Edamam Nutrition api
86
+ email:
87
+ - olalekan.eyiowuawi@andela.com
88
+ - chris@gobble.com
89
+ - mayowa.pitan@andela.com
90
+ executables: []
91
+ extensions: []
92
+ extra_rdoc_files: []
93
+ files:
94
+ - ".gitignore"
95
+ - ".hound.yml"
96
+ - ".rspec"
97
+ - ".rubocop.yml"
98
+ - ".travis.yml"
99
+ - CODE_OF_CONDUCT.md
100
+ - Gemfile
101
+ - LICENSE
102
+ - README.md
103
+ - Rakefile
104
+ - bin/console
105
+ - bin/setup
106
+ - edamam-ruby.gemspec
107
+ - lib/edamam-ruby.rb
108
+ - lib/edamam-ruby/Utils/api.rb
109
+ - lib/edamam-ruby/Utils/connection.rb
110
+ - lib/edamam-ruby/Utils/errors.rb
111
+ - lib/edamam-ruby/client.rb
112
+ - lib/edamam-ruby/food_database.rb
113
+ - lib/edamam-ruby/version.rb
114
+ homepage: https://github.com/gobble/edamam-ruby
115
+ licenses: []
116
+ metadata:
117
+ allowed_push_host: https://rubygems.org
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.6.6
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: This a ruby wrapper for the Edamam Nutrition api
138
+ test_files: []