Class: Leaflyapi::Strains

Inherits:
Object
  • Object
show all
Defined in:
lib/leaflyapi.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Strains

Returns a new instance of Strains.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/leaflyapi.rb', line 39

def initialize(data)
  @id = data["Id"]
  @key = data["Key"]
  @name = data["Name"]
  @category = data["Category"]
  @symbol = data["Symmbol"]
  @description = data["Abstract"]
  @url = data["Url"]
  @rating = data["Rating"]
  @effects = data["Effects"]
  @medical_uses = data["Medical"]
  @side_effects = data["Negative"]
  @reviews = data["Reviews"]
end

Instance Attribute Details

#categoryObject (readonly)

Returns the value of attribute category.



35
36
37
# File 'lib/leaflyapi.rb', line 35

def category
  @category
end

#descriptionObject (readonly)

Returns the value of attribute description.



35
36
37
# File 'lib/leaflyapi.rb', line 35

def description
  @description
end

#effectsObject (readonly)

Returns the value of attribute effects.



35
36
37
# File 'lib/leaflyapi.rb', line 35

def effects
  @effects
end

#idObject (readonly)

Returns the value of attribute id.



35
36
37
# File 'lib/leaflyapi.rb', line 35

def id
  @id
end

#keyObject (readonly)

Returns the value of attribute key.



35
36
37
# File 'lib/leaflyapi.rb', line 35

def key
  @key
end

#medical_usesObject (readonly)

Returns the value of attribute medical_uses.



35
36
37
# File 'lib/leaflyapi.rb', line 35

def medical_uses
  @medical_uses
end

#nameObject (readonly)

Returns the value of attribute name.



35
36
37
# File 'lib/leaflyapi.rb', line 35

def name
  @name
end

#overviewObject (readonly)

Returns the value of attribute overview.



35
36
37
# File 'lib/leaflyapi.rb', line 35

def overview
  @overview
end

#ratingObject (readonly)

Returns the value of attribute rating.



35
36
37
# File 'lib/leaflyapi.rb', line 35

def rating
  @rating
end

#reviewsObject (readonly)

Returns the value of attribute reviews.



35
36
37
# File 'lib/leaflyapi.rb', line 35

def reviews
  @reviews
end

#side_effectsObject (readonly)

Returns the value of attribute side_effects.



35
36
37
# File 'lib/leaflyapi.rb', line 35

def side_effects
  @side_effects
end

#symbolObject (readonly)

Returns the value of attribute symbol.



35
36
37
# File 'lib/leaflyapi.rb', line 35

def symbol
  @symbol
end

#urlObject (readonly)

Returns the value of attribute url.



35
36
37
# File 'lib/leaflyapi.rb', line 35

def url
  @url
end

Class Method Details

.allObject



7
8
9
10
11
# File 'lib/leaflyapi.rb', line 7

def self.all
  response = ::HTTParty.get("http://www.leafly.com/api/strains")
  strains_json = ::JSON.parse(response.body)
  strains_json.collect {|strain| new (strain)}
end

.find_by_category(category) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/leaflyapi.rb', line 27

def self.find_by_category(category)
  response = ::HTTParty.get("http://www.leafly.com/api/strains?category=#{category}")
  strains_json = ::JSON.parse(response.body)
  strains_json.map do |strain|
    strain["Key"]
  end
end

.find_by_key(key) ⇒ Object



21
22
23
24
25
# File 'lib/leaflyapi.rb', line 21

def self.find_by_key(key)
  response = ::HTTParty.get("http://www.leafly.com/api/details/#{key}")
  strain_json = ::JSON.parse(response.body)
  new (strain_json)
end

.keysObject



13
14
15
16
17
18
19
# File 'lib/leaflyapi.rb', line 13

def self.keys
  response = ::HTTParty.get("http://www.leafly.com/api/strains")
  strains_json = ::JSON.parse(response.body)
  strains_json.map do |strain|
    strain["Key"]
  end
end