class Nanopop::Picture

Constants

AVATAR_URL
URL

Public Class Methods

latest(qty) click to toggle source
# File lib/nanopop/picture.rb, line 24
def self.latest qty
  raise Nanopop::UndefinedToken unless Nanopop.configuration.token

  response = fetch(:latest, numberOfPictures: qty)
  doc = Nokogiri.XML(response)

  doc.search('PictureLatest').map do |item|
    ats = {}
    item.element_children.each do |at|
      key = at.name.scan(/_x003C_(.+)_x003E_k__BackingField/).flatten.first.underscore
      value = at.text
      ats[key.to_sym] = value
    end
    new(ats)
  end
end
new(ats) click to toggle source
# File lib/nanopop/picture.rb, line 12
def initialize ats
  @ats = ats
end

Private Class Methods

fetch(method, params={}) click to toggle source
# File lib/nanopop/picture.rb, line 49
def self.fetch method, params={}
  url = "#{Nanopop::API_URL}/picture/#{method}/?#{query_string(params)}"
  RestClient.get(url, {"Authorization-Token" => Nanopop.configuration.token})
end
query_string(hash) click to toggle source
# File lib/nanopop/picture.rb, line 43
def self.query_string hash
  uri = Addressable::URI.new
  uri.query_values = hash
  uri.query
end

Public Instance Methods

avatar_url() click to toggle source
# File lib/nanopop/picture.rb, line 20
def avatar_url
  AVATAR_URL % [adjust(user_id), user_picture_filename]
end
url() click to toggle source
# File lib/nanopop/picture.rb, line 16
def url
  URL % [adjust(task_id), picture_filename]
end

Private Instance Methods

adjust(value) click to toggle source
# File lib/nanopop/picture.rb, line 54
def adjust value
  value.rjust(7, '0')
end
method_missing(method, params={}) click to toggle source
# File lib/nanopop/picture.rb, line 58
def method_missing method, params={}
  @ats[method]
end