class Taggun::Parser

Basic parser class

Public Class Methods

new() click to toggle source
# 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

Public Instance Methods

from_encoded(method, encoded) click to toggle source
# File lib/taggun/parser.rb, line 37
def from_encoded(method, encoded)
  # TODO
end
from_file(method, file) click to toggle source
# File lib/taggun/parser.rb, line 33
def from_file(method, file)
  # TODO
end
from_storage(method, md5) click to toggle source
# File lib/taggun/parser.rb, line 41
def from_storage(method, md5)
  # TODO
end
from_url(url, method = Taggun::SIMPLE) click to toggle source

Parse the receipt from url

Arguments

  • url - The URL to parse from as String

  • method - The method to get. Valid values are Taggun::Simple and Taggun::Verbose. Default is Taggun::Simple

Returns a JSON with the result from Taggun.io

# 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) click to toggle source
# 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