Class: Taggun::Parser
- Inherits:
-
Object
- Object
- Taggun::Parser
- Defined in:
- lib/taggun/parser.rb
Overview
Basic parser class
Instance Method Summary collapse
- #from_encoded(method, encoded) ⇒ Object
- #from_file(method, file) ⇒ Object
- #from_storage(method, md5) ⇒ Object
-
#from_url(url, method = Taggun::SIMPLE) ⇒ Object
Parse the receipt from url.
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
- #parse(uri, body) ⇒ Object
Constructor Details
#initialize ⇒ Parser
Returns a new instance of Parser.
6 7 8 9 |
# File 'lib/taggun/parser.rb', line 6 def initialize raise(ArgumentError, 'Initializer missing. See README for details') if Taggun.configuration.nil? raise(ArgumentError, 'Api Key not set. See README for details.') if Taggun.configuration.api_key.nil? end |
Instance Method Details
#from_encoded(method, encoded) ⇒ Object
37 38 39 |
# File 'lib/taggun/parser.rb', line 37 def from_encoded(method, encoded) # TODO end |
#from_file(method, file) ⇒ Object
33 34 35 |
# File 'lib/taggun/parser.rb', line 33 def from_file(method, file) # TODO end |
#from_storage(method, md5) ⇒ Object
41 42 43 |
# File 'lib/taggun/parser.rb', line 41 def from_storage(method, md5) # TODO end |
#from_url(url, method = Taggun::SIMPLE) ⇒ Object
Parse the receipt from url
Arguments
-
url
- The URL to parse from asString
-
method
- The method to get. Valid values areTaggun::Simple
andTaggun::Verbose
. Default isTaggun::Simple
Returns a JSON
with the result from Taggun.io
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/taggun/parser.rb', line 21 def from_url(url, method = Taggun::SIMPLE) uri = URI.parse("#{BASE_URL}/#{RECEIPT_URL}/#{API_VERSION}/#{method}/#{URL}") body = { url: url, incognito: Taggun.configuration.incognito, refresh: Taggun.configuration.refresh } parse(uri, body) end |
#parse(uri, body) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/taggun/parser.rb', line 45 def parse(uri, body) http = ::Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = ::Net::HTTP::Post.new( uri.request_uri, 'Content-Type': 'application/json' ) request['apikey'] = Taggun.configuration.api_key request.body = body.to_json response = http.request(request) JSON.parse(response.body) end |