Module: AisleFinder

Defined in:
lib/aislefinder.rb,
lib/aislefinder/version.rb

Constant Summary collapse

VERSION =
"0.0.02"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.apikeyObject

Returns the value of attribute apikey.



16
17
18
# File 'lib/aislefinder.rb', line 16

def apikey
  @apikey
end

.base_uriObject

Returns the value of attribute base_uri.



15
16
17
# File 'lib/aislefinder.rb', line 15

def base_uri
  @base_uri
end

Class Method Details

.find_all_us_statesObject



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/aislefinder.rb', line 59

def self.find_all_us_states
  # http://www.SupermarketAPI.com/api.asmx/AllUSStates
  response = Typhoeus::Request.get( "#{base_uri}/AllUSStates") 
  if response.code == 200 
    doc = Nokogiri::XML(response.body)
    array_of_store_states = ArrayOfStoreState.parse(doc)
    array_of_store_states.store_state_sets 
  elsif response.code == 404
    nil 
  else 
    raise response.body 
  end 
end

.find_by_product_id(id) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/aislefinder.rb', line 39

def self.find_by_product_id(id) 
  # hhttp://www.supermarketapi.com/api.asmx/SearchByItemID?APIKEY=APIKEY&ItemId=32372
  response = Typhoeus::Request.get( "#{base_uri}/SearchByItemID?APIKEY=#{apikey}&ItemId=#{id}") 
  if response.code == 200 
    doc = Nokogiri::XML(response.body)
    array_of_products = ArrayOfProduct.parse(doc)
    
    # should be a 404 (not found) :(
    if array_of_products.product_sets && array_of_products.product_sets.first.item_name != 'NOITEM'
      array_of_products.product_sets
    else
      nil
    end
  elsif response.code == 404
    nil 
  else 
    raise response.body 
  end 
end

.find_by_product_name(name) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/aislefinder.rb', line 19

def self.find_by_product_name(name) 
  # http://www.SupermarketAPI.com/api.asmx/SearchByProductName?APIKEY=APIKEY&ItemName=Parsley
  response = Typhoeus::Request.get( "#{base_uri}/SearchByProductName?APIKEY=#{apikey}&ItemName=#{name}") 
  if response.code == 200 
    doc = Nokogiri::XML(response.body)
    array_of_products = ArrayOfProduct.parse(doc)
    
    # should be a 404 (not found) :(
    if array_of_products.product_sets && array_of_products.product_sets.first.item_name != 'NOITEM'
      array_of_products.product_sets
    else
      nil
    end
  elsif response.code == 404
    nil 
  else 
    raise response.body 
  end 
end

.find_cities_by_state(state) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/aislefinder.rb', line 73

def self.find_cities_by_state(state)
  #http://www.supermarketapi.com/api.asmx/CitiesByState?APIKEY=APIKEY&SelectedState=CA
  response = Typhoeus::Request.get( "#{base_uri}/CitiesByState?APIKEY=#{apikey}&SelectedState=#{state}") 
  if response.code == 200 
    doc = Nokogiri::XML(response.body)
    array_of_store_city = ArrayOfStoreCity.parse(doc)
    array_of_store_city.store_city_sets 
  elsif response.code == 404
    nil 
  else 
    raise response.body 
  end  
  
end

.find_product_names_by_full_name(full_name) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/aislefinder.rb', line 88

def self.find_product_names_by_full_name(full_name)
  #http://www.supermarketapi.com/api.asmx/GetGroceries?APIKEY=APIKEY&SearchText=Apple
  response = Typhoeus::Request.get( "#{base_uri}/GetGroceries?APIKEY=#{apikey}&SearchText=#{full_name}") 
  if response.code == 200 
    doc = Nokogiri::XML(response.body)
    array_of_string = ArrayOfString.parse(doc)
    array_of_string.string_sets 
  elsif response.code == 404
    nil 
  else 
    raise response.body 
  end 
end

.find_products_by_store_id(store_id, name) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/aislefinder.rb', line 116

def self.find_products_by_store_id(store_id, name)
  # http://www.supermarketapi.com/api.asmx/SearchForItem?APIKEY=APIKEY&StoreId=b97153fc14&ItemName=Apple
  response = Typhoeus::Request.get( "#{base_uri}/SearchForItem?APIKEY=#{apikey}&StoreId=#{store_id}&ItemName=#{name}") 
  if response.code == 200 
     doc = Nokogiri::XML(response.body)
     array_of_products = ArrayOfProduct.parse(doc)
     # should be a 404 (not found) :(
     if array_of_products.product_sets && array_of_products.product_sets.first.item_name != 'NOITEM'
       array_of_products.product_sets
     else
       nil
     end
   elsif response.code == 404
     nil 
   else 
     raise response.body 
   end
end

.find_stores_by_city_and_state(city, state) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/aislefinder.rb', line 135

def self.find_stores_by_city_and_state(city,state)
  #http://http://www.SupermarketAPI.com/api.asmx/StoresByCityState?APIKEY=APIKEY&SelectedCity=San Francisco&SelectedState=CA
  city=CGI::escape(city)
  response = Typhoeus::Request.get( "#{base_uri}/StoresByCityState?APIKEY=#{apikey}&SelectedCity=#{city}&SelectedState=#{state}") 
  if response.code == 200 
    doc = Nokogiri::XML(response.body)
    array_of_store = ArrayOfStore.parse(doc)
    array_of_store.store_sets 
  elsif response.code == 404
    nil 
  else 
    raise response.body 
  end 
end

.find_stores_by_name(store) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/aislefinder.rb', line 102

def self.find_stores_by_name(store)
  #http://www.supermarketapi.com/api.asmx/ReturnStoresByName?APIKEY=APIKEY&StoreName=Safeway
  response = Typhoeus::Request.get( "#{base_uri}/ReturnStoresByName?APIKEY=#{apikey}&StoreName=#{store}") 
  if response.code == 200 
    doc = Nokogiri::XML(response.body)
    array_of_store = ArrayOfStore.parse(doc)
    array_of_store.store_sets 
  elsif response.code == 404
    nil 
  else 
    raise response.body 
  end 
end

.find_stores_by_zip(zip) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/aislefinder.rb', line 150

def self.find_stores_by_zip(zip)
  #http://www.SupermarketAPI.com/api.asmx/StoresByZip?APIKEY=APIKEY&ZipCode=95130
  response = Typhoeus::Request.get( "#{base_uri}/StoresByZip?APIKEY=#{apikey}&ZipCode=#{zip}") 
  if response.code == 200 
    doc = Nokogiri::XML(response.body)
    array_of_store = ArrayOfStore.parse(doc)
    array_of_store.store_sets 
  elsif response.code == 404
    nil 
  else 
    raise response.body 
  end 
end