Skip to content
This repository was archived by the owner on Mar 27, 2023. It is now read-only.

Commit 9aea783

Browse files
committed
Merge pull request #6 from mounarajan/master
Updated README.md
2 parents afa1fd1 + 38ecee5 commit 9aea783

File tree

1 file changed

+60
-70
lines changed

1 file changed

+60
-70
lines changed

README.md

Lines changed: 60 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
semantics3-ruby is a Ruby client for accessing the Semantics3 Products API, which provides structured information, including pricing histories, for a large number of products.
44
See https://www.semantics3.com for more information.
55

6-
Quickstart guide: https://www.semantics3.com/quickstart
76
API documentation can be found at https://www.semantics3.com/docs/
87

98
## Installation
@@ -46,106 +45,99 @@ API_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
4645
sem3 = Semantics3::Products.new(API_KEY,API_SECRET)
4746
```
4847

49-
### First Query aka 'Hello World':
48+
### First Request aka 'Hello World':
5049

51-
Let's make our first query! For this query, we are going to search for all Toshiba products that fall under the category of "Computers and Accessories", whose cat_id is 4992.
50+
Let's run our first request! We are going to run a simple search fo the word "iPhone" as follows:
5251

5352
```ruby
54-
# Build the query
55-
sem3.products_field( "cat_id", 4992 )
56-
sem3.products_field( "brand", "Toshiba" )
53+
# Build the request
54+
sem3.products_field( "search", "iphone" )
5755

58-
# Make the query
56+
# Run the request
5957
productsHash = sem3.get_products()
6058

61-
# View the results of the query
59+
# View the results of the request
6260
puts productsHash.to_json
6361
```
6462

65-
## Examples
63+
## Sample Requests
6664

67-
The following examples show you how to interface with some of the core functionality of the Semantics3 Products API. For more detailed examples check out the Quickstart guide: https://www.semantics3.com/quickstart
65+
The following requests show you how to interface with some of the core functionality of the Semantics3 Products API:
6866

69-
### Explore the Category Tree
67+
### Pagination
7068

71-
In this example we are going to be accessing the categories endpoint. We are going to be specifically exploring the "Computers and Accessories" category, which has a cat_id of 4992. For more details regarding our category tree and associated cat_ids check out our API docs at https://www.semantics3.com/docs
69+
The example in our "Hello World" script returns the first 10 results. In this example, we'll scroll to subsequent pages, beyond our initial request:
7270

7371
```ruby
74-
# Build the query
75-
sem3.categories_field( "cat_id", 4992 )
72+
# Build the request
73+
sem3.products_field( "search", "iphone" )
7674

77-
# Make the query
78-
categoriesHash = sem3.get_categories()
75+
# Run the request
76+
productsHash = sem3.get_products()
7977

80-
# View the results of the query
81-
puts categoriesHash.to_json
82-
```
78+
# View the results of the request
79+
puts productsHash.to_json
8380

84-
### Nested Search Query
81+
# Goto the next 'page'
82+
page = 0
83+
while (productsHash = sem3.iterate_products) do
84+
page = page + 1
85+
puts "We are at page = #{page}"
86+
puts "The results for this page are:\n"
87+
puts productsHash.to_json
88+
end
89+
```
8590

86-
You can construct complex queries by just repeatedly calling the products_field() or add() methods. Here is how we translate the following JSON query - '{"cat_id":4992,"brand":"Toshiba","weight":{"gte":1000000,"lt":1500000},"sitedetails":{"name":"newegg.com","latestoffers":{"currency":"USD","price":{"gte":100}}}}'.
91+
### UPC Query
8792

88-
This query returns all Toshiba products within a certain weight range narrowed down to just those that retailed recently on newegg.com for >= USD 100.
93+
Running a UPC/EAN/GTIN query is as simple as running a search query:
8994

9095
```ruby
91-
# Build the query
92-
sem3.products_field( "cat_id", 4992 )
93-
sem3.products_field( "brand", "Toshiba" )
94-
sem3.products_field( "weight", "gte", 1000000 )
95-
sem3.products_field( "weight", "lt", 1500000 )
96-
sem3.products_field( "sitedetails", "name", "newegg.com" )
97-
sem3.products_field( "sitedetails", "latestoffers", "currency", "USD" )
98-
sem3.products_field( "sitedetails", "latestoffers", "price", "gte", 100 )
96+
# Build the request
97+
sem3.products_field( "upc", "883974958450" )
98+
sem3.products_field( "field", ["name","gtins"] )
99+
100+
# Run the request
101+
productsHash = sem3.get_products()
99102

100-
# Let's make a modification - say we no longer want the weight attribute
101-
sem3.remove( "products", "brand", "weight" )
103+
# View the results of the request
104+
puts productsHash.to_json
105+
```
102106

103-
# Let's view the JSON query we just constructed. This is a good starting point to debug, if you are getting incorrect
104-
# results for your query
105-
constructedJson = sem3.get_query_json( "products" )
106-
puts constructedJson
107+
### URL Query
107108

108-
# Make the query
109-
productsHash = sem3.get_products
109+
Get the picture? You can run URL queries as follows:
110110

111-
# View the results of the query
111+
```ruby
112+
sem3.products_field( "url", "http://www.walmart.com/ip/15833173" )
113+
productsHash = sem3.get_products()
112114
puts productsHash.to_json
113115
```
114116

115-
### Pagination
117+
### Price Filter
116118

117-
Let's now look at doing pagination, continuing from where we stopped previously.
119+
Filter by price using the "lt" (less than) tag:
118120

119121
```ruby
120-
# Goto the next 'page'
121-
page = 0
122-
while (productsHash = sem3.iterate_products) do
123-
page = page + 1
124-
puts "Iterating through page: #{page}"
125-
end
122+
sem3.products_field( "search", "iphone" )
123+
sem3.products_field( "price", "lt", 300 )
124+
productsHash = sem3.get_products()
125+
puts productsHash.to_json
126126
```
127127

128-
### Explore Price Histories
128+
### Category ID Query
129129

130-
We shall use the add() method, which allows you to access any of the supported endpoints by just specifiying the name of the endpoint. add( "products", param1, param2, ...) is the equivalent of products_field( param1, param2, ... ), add( "offers", param1, param2, ... ) is the equivalent of offers_field( param1, param2, ...)
131-
132-
For this example, we are going to look at a particular product that is sold by select mercgants and whose price is >= USD 30 and seen after a specific date (specified as a UNIX timestamp).
130+
To lookup details about a cat_id, run your request against the categories resource:
133131

134132
```ruby
135-
# Build the query
136-
sem3.add( "offers", "sem3_id", "4znupRCkN6w2Q4Ke4s6sUC")
137-
sem3.add( "offers", "seller", ["LFleurs","Frys","Walmart"] )
138-
sem3.add( "offers", "currency", "USD")
139-
sem3.add( "offers", "price", "gte", 30)
140-
sem3.add( "offers", "lastrecorded_at", "gte", 1348654600)
141-
142-
# Make the query
143-
offersHash = sem3.get_offers
144-
#Alternatively we could also do
145-
offersHash = sem3.run_query( "offers" )
146-
147-
# View the results of the query
148-
puts offersHash.to_json
133+
# Build the request
134+
sem3.products_field( "cat_id", 4992 )
135+
136+
# Run the request
137+
productsHash = sem3.get_products()
138+
139+
# View the results of the request
140+
puts productsHash.to_json
149141
```
150142

151143
## Contributing
@@ -154,11 +146,11 @@ Use GitHub's standard fork/commit/pull-request cycle. If you have any questions
154146

155147
## Author
156148

157-
* Sivamani VARUN <varun@semantics3.com>
149+
* Mounarajan <mounarajan@semantics3.com>
158150

159151
## Copyright
160152

161-
Copyright (c) 2013 Semantics3 Inc.
153+
Copyright (c) 2015 Semantics3 Inc.
162154

163155
## License
164156

@@ -180,6 +172,4 @@ Copyright (c) 2013 Semantics3 Inc.
180172
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
181173
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
182174
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
183-
DEALINGS IN THE SOFTWARE.
184-
185-
175+
DEALINGS IN THE SOFTWARE.

0 commit comments

Comments
 (0)