Skip to content

Instantly share code, notes, and snippets.

@benhorne44
Created January 2, 2014 21:28
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benhorne44/8227259 to your computer and use it in GitHub Desktop.
Save benhorne44/8227259 to your computer and use it in GitHub Desktop.
require 'faraday'
require 'json'
class Strains
def self.all_strains
response = Faraday.get("http://www.leafly.com/api/strains")
strains_json = JSON.parse(response.body)
strains_json.collect {|strain| new (strain)}
end
def self.find_all_keys
response = Faraday.get("http://www.leafly.com/api/strains")
strains_json = JSON.parse(response.body)
strains_json.collect do |strain|
strain["Key"]
end
end
def self.find_by_key(key)
response = Faraday.get("http://www.leafly.com/api/details/#{key}")
strain_json = JSON.parse(response.body)
new (strain_json)
end
def self.find_by_category(category)
response = Faraday.get("http://www.leafly.com/api/strains?category=#{category}")
strains_json = JSON.parse(response.body)
strains_json.collect do |strain|
strain["Key"]
end
end
attr_reader :key, :effects, :id, :name, :category,
:description, :symbol, :overview, :url,
:rating, :medical_uses, :side_effects, :reviews
def initialize(data)
@key = data["Key"]
@id = data["Id"]
@name = data["Name"]
@category = data["Category"]
@description = data["Abstract"]
@symbol = data["Symbol"]
@overview = data["Overview"]
@url = data["Url"]
@rating = data["Rating"]
@effects = data["Effects"] #returns an array of hashes for each effect
@medical_uses = data["Medical"]
@side_effects = data["Negative"]
@reviews = data["Reviews"]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment