yahoo_shopping_search 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +61 -0
- data/LICENSE.txt +21 -0
- data/README.md +73 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/yahoo_shopping_search.rb +30 -0
- data/lib/yahoo_shopping_search/clients/base.rb +73 -0
- data/lib/yahoo_shopping_search/clients/item.rb +17 -0
- data/lib/yahoo_shopping_search/config.rb +16 -0
- data/lib/yahoo_shopping_search/resources/item.rb +18 -0
- data/lib/yahoo_shopping_search/responses/base.rb +59 -0
- data/lib/yahoo_shopping_search/responses/item.rb +80 -0
- data/lib/yahoo_shopping_search/version.rb +5 -0
- data/yahoo_shopping_search.gemspec +43 -0
- metadata +137 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 72cc709a82d128b0b51f77b80e4d14ec9b34858922c69e70b4a030bc1363e44f
|
4
|
+
data.tar.gz: bfd45624d8ffe285227d9b85ded501b18df0ac11b6097ece06fd3887ff5ea084
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 797e36e02aac5e327d5ba0f50a6bfd7ba142302ff91892775c90f90a0f31b1122048232ecf1b3f7c8bb3ad1ebb3974d8a1f6e649d5e5b6e844f0f8876d72ff35
|
7
|
+
data.tar.gz: 568afb81757b474dc282afd12e41497e66025fea0331ab91f2a441ce6aea0a611b9e850997c806a8a48b88ca1dad5be7ce799bfadb5caa6544eca5500662b29c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at orehaorz@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
yahoo_shopping_search (0.1.0)
|
5
|
+
activesupport (>= 6.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activesupport (6.1.3.1)
|
11
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
|
+
i18n (>= 1.6, < 2)
|
13
|
+
minitest (>= 5.1)
|
14
|
+
tzinfo (~> 2.0)
|
15
|
+
zeitwerk (~> 2.3)
|
16
|
+
addressable (2.7.0)
|
17
|
+
public_suffix (>= 2.0.2, < 5.0)
|
18
|
+
concurrent-ruby (1.1.8)
|
19
|
+
crack (0.4.5)
|
20
|
+
rexml
|
21
|
+
diff-lcs (1.4.4)
|
22
|
+
hashdiff (1.0.1)
|
23
|
+
i18n (1.8.10)
|
24
|
+
concurrent-ruby (~> 1.0)
|
25
|
+
minitest (5.14.4)
|
26
|
+
public_suffix (4.0.6)
|
27
|
+
rake (10.5.0)
|
28
|
+
rexml (3.2.5)
|
29
|
+
rspec (3.10.0)
|
30
|
+
rspec-core (~> 3.10.0)
|
31
|
+
rspec-expectations (~> 3.10.0)
|
32
|
+
rspec-mocks (~> 3.10.0)
|
33
|
+
rspec-core (3.10.1)
|
34
|
+
rspec-support (~> 3.10.0)
|
35
|
+
rspec-expectations (3.10.1)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.10.0)
|
38
|
+
rspec-mocks (3.10.2)
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
+
rspec-support (~> 3.10.0)
|
41
|
+
rspec-support (3.10.2)
|
42
|
+
tzinfo (2.0.4)
|
43
|
+
concurrent-ruby (~> 1.0)
|
44
|
+
webmock (3.12.2)
|
45
|
+
addressable (>= 2.3.6)
|
46
|
+
crack (>= 0.3.2)
|
47
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
48
|
+
zeitwerk (2.4.2)
|
49
|
+
|
50
|
+
PLATFORMS
|
51
|
+
ruby
|
52
|
+
|
53
|
+
DEPENDENCIES
|
54
|
+
bundler (~> 2.0)
|
55
|
+
rake (~> 10.0)
|
56
|
+
rspec (~> 3.0)
|
57
|
+
webmock (~> 3.0)
|
58
|
+
yahoo_shopping_search!
|
59
|
+
|
60
|
+
BUNDLED WITH
|
61
|
+
2.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 otukutun
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# YahooShoppingSearch
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/yahoo_shopping_search`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'yahoo_shopping_search'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install yahoo_shopping_search
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
### Preparation
|
26
|
+
|
27
|
+
Before using this, Please get api key from [this](https://developer.yahoo.co.jp/start/).
|
28
|
+
|
29
|
+
### API Detail
|
30
|
+
|
31
|
+
If You want to know API detail, Please read [this](https://developer.yahoo.co.jp/webapi/shopping/shopping/v3/itemsearch.html).
|
32
|
+
|
33
|
+
### Initialize app id and affiliate id
|
34
|
+
|
35
|
+
You can initialize app id and affiliate id like a below code.
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
YahooShoppingSearch.configure do |config|
|
39
|
+
config.app_id = 'YOUR APP ID' # required
|
40
|
+
config.affiliate_type = 'YOUR AFFILIATE TYPE' # optional
|
41
|
+
config.sid = 'YOUR AFFILIATE SID' # optional
|
42
|
+
config.pid = 'YOUR AFFILIATE PID' # optional
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
### Search Shopping Item
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
result = YahooShoppingSearch::Clients::Item.search(keyword: 'よなよなエール')
|
50
|
+
# Fetch data
|
51
|
+
result.each { |item| p item }
|
52
|
+
# if you want to go to next page
|
53
|
+
result.next_page!
|
54
|
+
# if next_page doesn't exist, NextPageNotFound Exception is raised.
|
55
|
+
```
|
56
|
+
|
57
|
+
## Development
|
58
|
+
|
59
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
60
|
+
|
61
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
62
|
+
|
63
|
+
## Contributing
|
64
|
+
|
65
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/yahoo_shopping_search. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
66
|
+
|
67
|
+
## License
|
68
|
+
|
69
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
70
|
+
|
71
|
+
## Code of Conduct
|
72
|
+
|
73
|
+
Everyone interacting in the YahooShoppingSearch project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/yahoo_shopping_search/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "yahoo_shopping_search"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yahoo_shopping_search/version'
|
4
|
+
require 'yahoo_shopping_search/config'
|
5
|
+
require 'yahoo_shopping_search/clients/base'
|
6
|
+
require 'yahoo_shopping_search/clients/item'
|
7
|
+
require 'yahoo_shopping_search/responses/base'
|
8
|
+
require 'yahoo_shopping_search/responses/item'
|
9
|
+
require 'yahoo_shopping_search/resources/item'
|
10
|
+
|
11
|
+
module YahooShoppingSearch
|
12
|
+
class BadRequestError < StandardError; end
|
13
|
+
class UnauthorizedError < StandardError; end
|
14
|
+
class ForbiddenError < StandardError; end
|
15
|
+
class NotFoundError < StandardError; end
|
16
|
+
class InternalServerError < StandardError; end
|
17
|
+
class ServiceUnavailableError < StandardError; end
|
18
|
+
|
19
|
+
class NextPageNotFound < StandardError; end
|
20
|
+
|
21
|
+
class << self
|
22
|
+
def configure
|
23
|
+
yield config
|
24
|
+
end
|
25
|
+
|
26
|
+
def config
|
27
|
+
@_config ||= ::YahooShoppingSearch::Config.new
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YahooShoppingSearch
|
4
|
+
module Clients
|
5
|
+
class Base
|
6
|
+
class << self
|
7
|
+
def search(params = {})
|
8
|
+
queries = params.merge(base_params).to_query
|
9
|
+
|
10
|
+
uri = URI.parse("#{url}?#{queries}")
|
11
|
+
req = Net::HTTP::Get.new uri
|
12
|
+
|
13
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
|
14
|
+
res = http.request(req)
|
15
|
+
case res
|
16
|
+
when Net::HTTPOK
|
17
|
+
return response_class_name.new(res.body, params)
|
18
|
+
when Net::HTTPBadRequest
|
19
|
+
raise BadRequestError.new(error_message(res))
|
20
|
+
when Net::HTTPUnauthorized
|
21
|
+
raise UnauthorizedError.new(error_message(res))
|
22
|
+
when Net::HTTPForbidden
|
23
|
+
raise ForbiddenError.new(error_message(res))
|
24
|
+
when Net::HTTPNotFound
|
25
|
+
raise NotFoundError.new(error_message(res))
|
26
|
+
when Net::HTTPInternalServerError
|
27
|
+
raise InternalServerError.new(error_message(res))
|
28
|
+
when Net::HTTPServiceUnavailable
|
29
|
+
raise ServiceUnavailableError.new(error_message(res))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def response_class_name
|
35
|
+
raise NotImplementedError
|
36
|
+
end
|
37
|
+
|
38
|
+
def url
|
39
|
+
raise NotImplementedError
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def error_message(res)
|
45
|
+
if xml_response?(res)
|
46
|
+
doc = REXML::Document.new(res.body)
|
47
|
+
hash = Hash.from_xml(doc.to_s)
|
48
|
+
return hash['Error']['Message']
|
49
|
+
end
|
50
|
+
|
51
|
+
json = JSON.parse(res.body)
|
52
|
+
json['Error']['Message']
|
53
|
+
end
|
54
|
+
|
55
|
+
def xml_response?(res)
|
56
|
+
res.header['content-type'].include?('text/xml')
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_query(params)
|
60
|
+
params.map { |k, v| "#{URI.encode(k)}=#{URI.encode(v)}" }.join('&')
|
61
|
+
end
|
62
|
+
|
63
|
+
def base_params
|
64
|
+
params = { appid: YahooShoppingSearch.config.app_id }
|
65
|
+
params[:affiliate_id] = YahooShoppingSearch.config.affiliate_id if YahooShoppingSearch.config.affiliate_id&.present?
|
66
|
+
params[:affiliate_type] = YahooShoppingSearch.config.affiliate_type if YahooShoppingSearch.config.affiliate_type&.present?
|
67
|
+
|
68
|
+
params
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YahooShoppingSearch
|
4
|
+
module Clients
|
5
|
+
class Item < Base
|
6
|
+
class << self
|
7
|
+
def response_class_name
|
8
|
+
Responses::Item
|
9
|
+
end
|
10
|
+
|
11
|
+
def url
|
12
|
+
'https://shopping.yahooapis.jp/ShoppingWebService/V3/itemSearch'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YahooShoppingSearch
|
4
|
+
class Config
|
5
|
+
attr_accessor :app_id, :affiliate_type, :sid, :pid
|
6
|
+
|
7
|
+
# REF: https://developer.yahoo.co.jp/appendix/shopping/affiliate.html
|
8
|
+
# @return [String]
|
9
|
+
def affiliate_id
|
10
|
+
return if sid.nil? || pid.nil?
|
11
|
+
|
12
|
+
base_url = 'https://ck.jp.ap.valuecommerce.com/servlet/referral'
|
13
|
+
URI.encode("#{base_url}?sid=#{sid}&pid=#{pid}&vc_url=")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YahooShoppingSearch
|
4
|
+
module Resources
|
5
|
+
class Item
|
6
|
+
# @param hash [Hash]
|
7
|
+
def initialize(hash)
|
8
|
+
@item = hash
|
9
|
+
end
|
10
|
+
|
11
|
+
# @param key [String]
|
12
|
+
# @return [Hash, nil]
|
13
|
+
def [](key)
|
14
|
+
@item[key]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YahooShoppingSearch
|
4
|
+
module Responses
|
5
|
+
class Base
|
6
|
+
include ::Enumerable
|
7
|
+
|
8
|
+
# @param body [String]
|
9
|
+
# @param params [Hash]
|
10
|
+
def initialize(body, params = {})
|
11
|
+
@body = JSON.parse(body)
|
12
|
+
@params = params
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return [Hash]
|
16
|
+
def body
|
17
|
+
@body
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [Hash]
|
21
|
+
def params
|
22
|
+
@params
|
23
|
+
end
|
24
|
+
|
25
|
+
# @note Implementation for Enumerable
|
26
|
+
def each(&block)
|
27
|
+
items.each(&block)
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [Array<YahooShoppingSearch::Resources::Base>]
|
31
|
+
def items
|
32
|
+
(sources || []).map do |source|
|
33
|
+
resource_class.new(source)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Specify class name
|
38
|
+
def sources
|
39
|
+
raise NotImplementedError
|
40
|
+
end
|
41
|
+
|
42
|
+
# Specify class name
|
43
|
+
def resource_class
|
44
|
+
raise NotImplementedError
|
45
|
+
end
|
46
|
+
|
47
|
+
# @param index [Integer]
|
48
|
+
# @return [YahooShoppingSearch::Resources::Base | nil]
|
49
|
+
def [](index)
|
50
|
+
items[index]
|
51
|
+
end
|
52
|
+
|
53
|
+
# @return [YahooShoppingSearch::Resources::Base | nil]
|
54
|
+
def last
|
55
|
+
items.last
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YahooShoppingSearch
|
4
|
+
module Responses
|
5
|
+
class Item < Base
|
6
|
+
|
7
|
+
# start + results sum's mixium is 1000
|
8
|
+
MAX_RESULTS_COUNT = 1000
|
9
|
+
DEFAULT_RESULTS_COUNT = 20
|
10
|
+
|
11
|
+
# @param body [String]
|
12
|
+
# @param params [Hash]
|
13
|
+
def initialize(body, params = {})
|
14
|
+
@body = JSON.parse(body)
|
15
|
+
@params = params
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [Boolean]
|
19
|
+
def has_next_page?
|
20
|
+
if total_results_count >= MAX_RESULTS_COUNT
|
21
|
+
MAX_RESULTS_COUNT >= start_position + results_count
|
22
|
+
else
|
23
|
+
total_results_count - start_position - results_count > 0
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [Array<YahooShoppingSearch::Resources::Item>]
|
28
|
+
def next_page!
|
29
|
+
raise NextPageNotFound.new('Next page not found') unless has_next_page?
|
30
|
+
@body = client_class.search(next_search_condition).body
|
31
|
+
@params = next_search_condition
|
32
|
+
|
33
|
+
items
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [Integer]
|
37
|
+
def start_position
|
38
|
+
@body['firstResultsPosition']
|
39
|
+
end
|
40
|
+
|
41
|
+
# @return [Integer]
|
42
|
+
def results_count
|
43
|
+
@body['totalResultsReturned']
|
44
|
+
end
|
45
|
+
|
46
|
+
# @return [Integer]
|
47
|
+
def total_results_count
|
48
|
+
@body['totalResultsAvailable']
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [Hash]
|
52
|
+
def search_condition
|
53
|
+
params
|
54
|
+
end
|
55
|
+
|
56
|
+
# @return [Hash]
|
57
|
+
def next_search_condition
|
58
|
+
condition = search_condition
|
59
|
+
condition['start'] = start_position + (condition['results'] || DEFAULT_RESULTS_COUNT)
|
60
|
+
|
61
|
+
condition
|
62
|
+
end
|
63
|
+
|
64
|
+
# @return [Array<Hash>]
|
65
|
+
def sources
|
66
|
+
body['hits']
|
67
|
+
end
|
68
|
+
|
69
|
+
# @return [ClassName]
|
70
|
+
def resource_class
|
71
|
+
::YahooShoppingSearch::Resources::Item
|
72
|
+
end
|
73
|
+
|
74
|
+
# @return [ClassName]
|
75
|
+
def client_class
|
76
|
+
::YahooShoppingSearch::Clients::Item
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "yahoo_shopping_search/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "yahoo_shopping_search"
|
8
|
+
spec.version = YahooShoppingSearch::VERSION
|
9
|
+
spec.authors = ["otukutun"]
|
10
|
+
spec.email = ["orehaorz@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{This is Yahoo Shopping Search API Wrapper}
|
13
|
+
spec.description = %q{This is minimum size wrapper for Yahoo Shopping Search API.}
|
14
|
+
spec.homepage = "https://github.com/otukutun/yahoo_shopping_search"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
21
|
+
spec.metadata["source_code_uri"] = "https://github.com/otukutun/yahoo_shopping_search"
|
22
|
+
spec.metadata["changelog_uri"] = "https://github.com/otukutun/yahoo_shopping_search/CHANGELOG.md"
|
23
|
+
else
|
24
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
25
|
+
"public gem pushes."
|
26
|
+
end
|
27
|
+
|
28
|
+
# Specify which files should be added to the gem when it is released.
|
29
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
30
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
31
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
32
|
+
end
|
33
|
+
spec.bindir = "exe"
|
34
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
35
|
+
spec.require_paths = ["lib"]
|
36
|
+
|
37
|
+
spec.add_dependency "activesupport", ">= 6.0"
|
38
|
+
|
39
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
40
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
41
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
42
|
+
spec.add_development_dependency "webmock", "~> 3.0"
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yahoo_shopping_search
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- otukutun
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-05-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '6.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '6.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description: This is minimum size wrapper for Yahoo Shopping Search API.
|
84
|
+
email:
|
85
|
+
- orehaorz@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- CHANGELOG.md
|
94
|
+
- CODE_OF_CONDUCT.md
|
95
|
+
- Gemfile
|
96
|
+
- Gemfile.lock
|
97
|
+
- LICENSE.txt
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- bin/console
|
101
|
+
- bin/setup
|
102
|
+
- lib/yahoo_shopping_search.rb
|
103
|
+
- lib/yahoo_shopping_search/clients/base.rb
|
104
|
+
- lib/yahoo_shopping_search/clients/item.rb
|
105
|
+
- lib/yahoo_shopping_search/config.rb
|
106
|
+
- lib/yahoo_shopping_search/resources/item.rb
|
107
|
+
- lib/yahoo_shopping_search/responses/base.rb
|
108
|
+
- lib/yahoo_shopping_search/responses/item.rb
|
109
|
+
- lib/yahoo_shopping_search/version.rb
|
110
|
+
- yahoo_shopping_search.gemspec
|
111
|
+
homepage: https://github.com/otukutun/yahoo_shopping_search
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
metadata:
|
115
|
+
homepage_uri: https://github.com/otukutun/yahoo_shopping_search
|
116
|
+
source_code_uri: https://github.com/otukutun/yahoo_shopping_search
|
117
|
+
changelog_uri: https://github.com/otukutun/yahoo_shopping_search/CHANGELOG.md
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubygems_version: 3.0.3
|
134
|
+
signing_key:
|
135
|
+
specification_version: 4
|
136
|
+
summary: This is Yahoo Shopping Search API Wrapper
|
137
|
+
test_files: []
|