fatsecret_lite 0.1.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91b136c33efde0f049afdf03e1ce4317cb43baae8ac84f14a9fd6a8a40fb686e
4
- data.tar.gz: b6f72949a99c9648e5ceba0f5bdfddcf1d1730742b1e1216ceb60f1f4d48cdff
3
+ metadata.gz: b8bfc4b156e147873fd3dfd1f025a321d438ac50b8574d63719b5aa4fc43d6cf
4
+ data.tar.gz: 870b5002e79ddd9039b7550d52f6e318030cbc779b1948a93ceca8b293579eb7
5
5
  SHA512:
6
- metadata.gz: 7dccc5a9fd227782e4990412ec9a4f236552a3bfa22f4d193addbb380ee001b2cad41cba5b4704156250f5ad462668b11c5dfd886652242d5606879f5afc9fcf
7
- data.tar.gz: e943712df335ec23f21a79cb341523e158eac99d746dd7e3ae1930b1ebab2d65733e3e088d807d0f47a605d5ae07369474fe4d280735f253f9110a335c79cf5b
6
+ metadata.gz: b92578269aeb7509316a66f38f162a01beef79d08b6b9671c0537bf407790b448bb0218fa9cbab26e407668ebc4ffb541cbca883f301758b15013e627b28ff63
7
+ data.tar.gz: 69615faadceb36b518c7d2525b20aba3f30266a073e6ef49e10f14372ceb664c6bb0bbb6c02459e727523680397977437eaaf1d7b052978d9e64837a42b98170
@@ -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.1"
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - KapilDevPal