Class: Newegg::Api
- Inherits:
-
Object
- Object
- Newegg::Api
- Defined in:
- lib/newegg/api.rb
Constant Summary collapse
- UserAgents =
{ iPhone: 'Newegg iPhone App / 4.3.1', Android: 'Newegg Android App / 3.3.3' }
- DefaultUserAgent =
:iPhone
Instance Attribute Summary collapse
-
#_categories ⇒ Object
Returns the value of attribute _categories.
-
#_id ⇒ Object
Returns the value of attribute _id.
-
#_stores ⇒ Object
Returns the value of attribute _stores.
-
#conn ⇒ Object
Returns the value of attribute conn.
Instance Method Summary collapse
-
#banners ⇒ Object
retrieve banners.
-
#categories(store_id) ⇒ Object
retrieve and populate list of categories for a given store_id.
-
#client_config ⇒ Object
retrieve iphone client config.
-
#combo_deals(item_number, options = {}) ⇒ Object
retrieve product combo deals given an item number.
-
#connection ⇒ Object
retrieve an active connection or establish a new connection.
-
#country ⇒ Object
retrieve tracking country.
-
#daily_deal ⇒ Object
retrieve daily deal.
-
#details(item_number) ⇒ Object
retrieve product details given an item number.
-
#exclusive_deals ⇒ Object
retrieve exclusive deal item.
-
#initialize ⇒ Api
constructor
A new instance of Api.
-
#keywords(keyword) ⇒ Object
retrieve related keywords given an keyword.
-
#navigate(store_id, category_id, node_id) ⇒ Object
retrieves information necessary to search for products, given the store_id, category_id, node_id.
-
#power_search(search_properties, options = {}) ⇒ Object
retrieves a single page of products given a query specified by an options hash.
-
#power_search_content(category_id) ⇒ Object
retrieve power search content given an category.
-
#query(options = {}) ⇒ Object
retrieves a single page of products given a query specified by an options hash.
-
#reviews(item_number, page_number = 1, options = {}) ⇒ Object
retrieve product reviews given an item number.
-
#search(options = {}) ⇒ Object
retrieves a single page of products given a query specified by an options hash.
-
#shell_shockers ⇒ Object
retrieve shell shocker items.
-
#shell_shockers_new ⇒ Object
retrieve new shell shocker items.
-
#shop_all_navigation ⇒ Object
retrieves stores.
- #shop_more_navigation ⇒ Object
-
#shopping_guide ⇒ Object
retrieve shopping guide config.
-
#specifications(item_number) ⇒ Object
retrieve product information given an item number.
-
#spotlight ⇒ Object
retrieve spotlight item.
-
#spotlights ⇒ Object
retrieve spotlights.
-
#store_content(store_id, category_id = -1,, node_id = -1,, store_type = 4, page_number = 1) ⇒ Object
retrieves store content.
-
#store_navigate(store_id, category_id = -1,, node_id = -1,, store_type = 4) ⇒ Object
retrieves information necessary to search for products, given the store_id, category_id, node_id.
-
#stores ⇒ Object
retrieve and populate a list of available stores.
Constructor Details
#initialize ⇒ Api
Returns a new instance of Api.
11 12 13 |
# File 'lib/newegg/api.rb', line 11 def initialize self._stores = [] end |
Instance Attribute Details
#_categories ⇒ Object
Returns the value of attribute _categories.
9 10 11 |
# File 'lib/newegg/api.rb', line 9 def _categories @_categories end |
#_id ⇒ Object
Returns the value of attribute _id.
9 10 11 |
# File 'lib/newegg/api.rb', line 9 def _id @_id end |
#_stores ⇒ Object
Returns the value of attribute _stores.
9 10 11 |
# File 'lib/newegg/api.rb', line 9 def _stores @_stores end |
#conn ⇒ Object
Returns the value of attribute conn.
9 10 11 |
# File 'lib/newegg/api.rb', line 9 def conn @conn end |
Instance Method Details
#banners ⇒ Object
retrieve banners
357 358 359 |
# File 'lib/newegg/api.rb', line 357 def JSON.parse(api_get('Promotions.egg', 'Banners').body) end |
#categories(store_id) ⇒ Object
retrieve and populate list of categories for a given store_id
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/newegg/api.rb', line 47 def categories(store_id) return [] if store_id.nil? response = api_get("Stores.egg", "Categories", store_id) categories = JSON.parse(response.body) categories = categories.collect do |category| Newegg::Category.new(category['Description'], category['CategoryType'], category['CategoryID'], category['StoreID'], category['ShowSeeAllDeals'], category['NodeId']) end categories end |
#client_config ⇒ Object
retrieve iphone client config
308 309 310 |
# File 'lib/newegg/api.rb', line 308 def client_config JSON.parse(api_get('Configurations.egg', 'IphoneClient').body) end |
#combo_deals(item_number, options = {}) ⇒ Object
retrieve product combo deals given an item number
262 263 264 265 266 267 268 269 270 |
# File 'lib/newegg/api.rb', line 262 def combo_deals(item_number, ={}) = {sub_category: -1, sort_field: 0, page_number: 1}.merge() params = { 'SubCategory' => [:sub_category], 'SortField' => [:sort_field], 'PageNumber' => [:page_number] } JSON.parse(api_get('Products.egg', item_number, 'ComboDeals', params).body) end |
#connection ⇒ Object
retrieve an active connection or establish a new connection
@ returns [Faraday::Connection] conn to the web service
20 21 22 23 24 25 26 27 |
# File 'lib/newegg/api.rb', line 20 def connection self.conn ||= Faraday.new(:url => 'http://www.ows.newegg.com') do |faraday| faraday.request :url_encoded # form-encode POST params faraday.response :logger # log requests to STDOUT faraday.adapter Faraday.default_adapter # make requests with Net::HTTP end end |
#country ⇒ Object
retrieve tracking country
294 295 296 |
# File 'lib/newegg/api.rb', line 294 def country JSON.parse(api_get('Tracking.egg', 'Country').body) end |
#daily_deal ⇒ Object
retrieve daily deal
322 323 324 |
# File 'lib/newegg/api.rb', line 322 def daily_deal JSON.parse(api_get('Promotions.egg', 'DailyDeal').body) end |
#details(item_number) ⇒ Object
retrieve product details given an item number
241 242 243 |
# File 'lib/newegg/api.rb', line 241 def details(item_number) JSON.parse(api_get('Products.egg', item_number, 'ProductDetails').body) end |
#exclusive_deals ⇒ Object
retrieve exclusive deal item
315 316 317 |
# File 'lib/newegg/api.rb', line 315 def exclusive_deals JSON.parse(api_get('Promotions.egg', 'ExclusiveDeals').body) end |
#keywords(keyword) ⇒ Object
retrieve related keywords given an keyword
232 233 234 |
# File 'lib/newegg/api.rb', line 232 def keywords(keyword) JSON.parse(api_get('AutoKeywords.egg', nil, nil, keyword: keyword).body) end |
#navigate(store_id, category_id, node_id) ⇒ Object
retrieves information necessary to search for products, given the store_id, category_id, node_id
67 68 69 70 |
# File 'lib/newegg/api.rb', line 67 def navigate(store_id, category_id, node_id) response = api_get("Stores.egg", "Navigation", "#{store_id}/#{category_id}/#{node_id}") categories = JSON.parse(response.body) end |
#power_search(search_properties, options = {}) ⇒ Object
retrieves a single page of products given a query specified by an options hash. See options below.
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/newegg/api.rb', line 210 def power_search(search_properties, ={}) = {page_number: 1, product_type: [], min_price: '', nvalues: '', srch_in_desc: '', brand_list: [], max_price: ''}.merge() request = { 'PageNumber' => [:page_number], 'ProductType' => [:product_type], 'SearchProperties' => search_properties, 'MinPrice' => [:min_price], 'NValues' => [:nvalues], 'SrchInDesc' => [:srch_in_desc], 'BrandList' => [:brand_list], 'MaxPrice' => [:max_price] } JSON.parse(api_post('PowerSearch.egg', nil, request).body, {quirks_mode: true}) end |
#power_search_content(category_id) ⇒ Object
retrieve power search content given an category
194 195 196 |
# File 'lib/newegg/api.rb', line 194 def power_search_content(category_id) JSON.parse(api_get('PowerSearchContent.egg', '0', "#{category_id}/-1").body) end |
#query(options = {}) ⇒ Object
retrieves a single page of products given a query specified by an options hash. See options below.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/newegg/api.rb', line 166 def query(={}) = {brand_list: [], search_properties: [], keyword: '', max_price:'', min_price: '', nvalue: '', product_type: [], page_number: 1, node_id: -1, category_id: -1, brand_id: -1, store_id: -1, store_type: -1, sub_category_id: -1}.merge() request = { 'BrandList' => [:brand_list], 'SearchProperties' => [:search_properties], 'Keyword' => [:keyword], 'MaxPrice' => [:max_price], 'MinPrice' => [:min_price], 'NValue' => [:nvalue], 'ProductType' => [:product_type], 'PageNumber' => [:page_number], 'NodeId' => [:node_id], 'CategoryId' => [:category_id], 'BrandId' => [:brand_id], 'StoreId' => [:store_id], 'StoreType' => [:store_type], 'SubCategoryId' => [:sub_category_id] } JSON.parse(api_post('Search.egg', 'Query', request).body, {quirks_mode: true}) end |
#reviews(item_number, page_number = 1, options = {}) ⇒ Object
retrieve product reviews given an item number
281 282 283 284 285 286 287 288 289 |
# File 'lib/newegg/api.rb', line 281 def reviews(item_number, page_number = 1, ={}) = {time: 'all', rating: 'All', sort: 'date posted'}.merge() params = { 'filter.time' => [:time], 'filter.rating' => [:rating], 'sort' => [:sort] } JSON.parse(api_get('Products.egg', item_number, "Reviewsinfo/#{page_number}", params).body) end |
#search(options = {}) ⇒ Object
retrieves a single page of products given a query specified by an options hash. See options below. node_id, page_number, and an optional sorting method
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/newegg/api.rb', line 127 def search(={}) = {store_id: -1, category_id: -1, sub_category_id: -1, node_id: -1, page_number: 1, sort: "FEATURED", keywords: ""}.merge() request = { 'IsUPCCodeSearch' => false, 'IsSubCategorySearch' => [:sub_category_id] > 0, 'isGuideAdvanceSearch' => false, 'StoreDepaId' => [:store_id], 'CategoryId' => [:category_id], 'SubCategoryId' => [:sub_category_id], 'NodeId' => [:node_id], 'BrandId' => -1, 'NValue' => "", 'Keyword' => [:keywords], 'Sort' => [:sort], 'PageNumber' => [:page_number] } JSON.parse(api_post("Search.egg", "Advanced", request).body, {quirks_mode: true}) end |
#shell_shockers ⇒ Object
retrieve shell shocker items
343 344 345 |
# File 'lib/newegg/api.rb', line 343 def shell_shockers JSON.parse(api_get('Promotions.egg', 'ShellShockers').body) end |
#shell_shockers_new ⇒ Object
retrieve new shell shocker items
350 351 352 |
# File 'lib/newegg/api.rb', line 350 def shell_shockers_new JSON.parse(api_get('Promotions.egg', 'NewShellShocker').body) end |
#shop_all_navigation ⇒ Object
retrieves stores
89 90 91 |
# File 'lib/newegg/api.rb', line 89 def JSON.parse(api_get('Store.egg', 'ShopAllNavigation').body) end |
#shop_more_navigation ⇒ Object
93 94 95 |
# File 'lib/newegg/api.rb', line 93 def JSON.parse(api_get('Store.egg', 'MoreNavigation').body) end |
#shopping_guide ⇒ Object
retrieve shopping guide config
301 302 303 |
# File 'lib/newegg/api.rb', line 301 def shopping_guide JSON.parse(api_get('Configurations.egg', 'ShoppingGuideConfig').body) end |
#specifications(item_number) ⇒ Object
retrieve product information given an item number
250 251 252 |
# File 'lib/newegg/api.rb', line 250 def specifications(item_number) JSON.parse(api_get("Products.egg", item_number, "Specification").body) end |
#spotlight ⇒ Object
retrieve spotlight item
329 330 331 |
# File 'lib/newegg/api.rb', line 329 def spotlight JSON.parse(api_get('Promotions.egg', 'Spotlight').body) end |
#spotlights ⇒ Object
retrieve spotlights
336 337 338 |
# File 'lib/newegg/api.rb', line 336 def spotlights JSON.parse(api_get('Promotions.egg', 'Spotlights').body) end |
#store_content(store_id, category_id = -1,, node_id = -1,, store_type = 4, page_number = 1) ⇒ Object
retrieves store content
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/newegg/api.rb', line 75 def store_content(store_id, category_id = -1, node_id = -1, store_type = 4, page_number = 1) params = { 'storeId' => store_id, 'categoryId' => category_id, 'nodeId' => node_id, 'storeType' => store_type, 'pageNumber' => page_number } JSON.parse(api_get('Stores.egg', 'Content', nil, params).body) end |
#store_navigate(store_id, category_id = -1,, node_id = -1,, store_type = 4) ⇒ Object
retrieves information necessary to search for products, given the store_id, category_id, node_id
105 106 107 108 109 110 111 112 113 |
# File 'lib/newegg/api.rb', line 105 def store_navigate(store_id, category_id = -1, node_id = -1, store_type = 4) params = { 'storeId' => store_id, 'categoryId' => category_id, 'nodeId' => node_id, 'storeType' => store_type } JSON.parse(api_get('Store.egg', 'storeNavigation', nil, params).body) end |
#stores ⇒ Object
retrieve and populate a list of available stores
32 33 34 35 36 37 38 39 40 |
# File 'lib/newegg/api.rb', line 32 def stores return self._stores if not self._stores.empty? response = api_get("Stores.egg") stores = JSON.parse(response.body) stores.each do |store| self._stores << Newegg::Store.new(store['Title'], store['StoreDepa'], store['StoreID'], store['ShowSeeAllDeals']) end self._stores end |