fatsecret_lite 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91b136c33efde0f049afdf03e1ce4317cb43baae8ac84f14a9fd6a8a40fb686e
4
- data.tar.gz: b6f72949a99c9648e5ceba0f5bdfddcf1d1730742b1e1216ceb60f1f4d48cdff
3
+ metadata.gz: c3176512cd1f08db8d7c8985e23ad46b1546b3af468318cd2feaade0238a8288
4
+ data.tar.gz: ec4f1b4c028b300595c3ee11db90950e3dcebea85bfe2134cfbf85d885228ff7
5
5
  SHA512:
6
- metadata.gz: 7dccc5a9fd227782e4990412ec9a4f236552a3bfa22f4d193addbb380ee001b2cad41cba5b4704156250f5ad462668b11c5dfd886652242d5606879f5afc9fcf
7
- data.tar.gz: e943712df335ec23f21a79cb341523e158eac99d746dd7e3ae1930b1ebab2d65733e3e088d807d0f47a605d5ae07369474fe4d280735f253f9110a335c79cf5b
6
+ metadata.gz: bb1ae96afde72d54aef2fa26d000777be4295ce24d39db3db9a154c69e13149d8002e111792c03745df4110e3da7e393ceb2c787baefd7c13a45da0c228e306a
7
+ data.tar.gz: e7960007a37e73ba936b382928c8ae37643713539e95d025b2df1ce692050e20eb96f002b99c62da692e639098d3cc9537e186a7373c4ed1aabc31fef3239559
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FatsecretLite
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
@@ -1,8 +1,63 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "fatsecret_lite/version"
1
+ # lib/fatsecret_lite.rb
2
+ require "oauth2"
3
+ require "rest-client"
4
+ require "json"
4
5
 
5
6
  module FatsecretLite
6
- class Error < StandardError; end
7
- # Your code goes here...
7
+ class Configuration
8
+ attr_accessor :client_id, :client_secret
9
+
10
+ def initialize
11
+ @client_id = nil
12
+ @client_secret = nil
13
+ end
14
+ end
15
+
16
+ @configuration = Configuration.new
17
+
18
+ class << self
19
+ def configure
20
+ yield(@configuration) if block_given?
21
+ end
22
+
23
+ def configuration
24
+ @configuration
25
+ end
26
+
27
+ def get_access_token
28
+ raise "Client ID and Client Secret must be configured" unless configuration.client_id && configuration.client_secret
29
+
30
+ client = OAuth2::Client.new(
31
+ configuration.client_id,
32
+ configuration.client_secret,
33
+ site: 'https://oauth.fatsecret.com',
34
+ token_url: 'https://oauth.fatsecret.com/connect/token'
35
+ )
36
+
37
+ token = client.client_credentials.get_token
38
+ token.token
39
+ end
40
+
41
+ def get_food_details(food_id)
42
+ access_token = get_access_token
43
+
44
+ response = RestClient.get(
45
+ 'https://platform.fatsecret.com/rest/server.api',
46
+ params: {
47
+ method: 'food.get.v2',
48
+ food_id: food_id,
49
+ format: 'json'
50
+ },
51
+ headers: {
52
+ Authorization: "Bearer #{access_token}"
53
+ }
54
+ )
55
+
56
+ JSON.parse(response.body)
57
+ rescue RestClient::ExceptionWithResponse => e
58
+ puts "Error: #{e.response}"
59
+ rescue StandardError => e
60
+ puts "An error occurred: #{e.message}"
61
+ end
62
+ end
8
63
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fatsecret_lite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - KapilDevPal