bing-content-api 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 +13 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +14 -0
- data/README.md +116 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bing-content-api.gemspec +42 -0
- data/lib/bing/content/api/batch.rb +35 -0
- data/lib/bing/content/api/batch_operation.rb +33 -0
- data/lib/bing/content/api/batch_processor.rb +38 -0
- data/lib/bing/content/api/client.rb +92 -0
- data/lib/bing/content/api/connector.rb +54 -0
- data/lib/bing/content/api/product.rb +53 -0
- data/lib/bing/content/api/response.rb +21 -0
- data/lib/bing/content/api/version.rb +7 -0
- data/lib/bing/content/api.rb +8 -0
- metadata +191 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dbbc646639a812235ba709b64c5245fb139537dd
|
4
|
+
data.tar.gz: e3fe5352ee776e9ad81396959624fdadf7cfca73
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dd90f22b8b2099a295d11bca44732e340dce86e9ebcc22b024ec134dd68ec2e2d4d9ba79d6ccd1f11879b92e62028a920e7fc0240334352c01a55d45586a2335
|
7
|
+
data.tar.gz: 7fa756165368b40e81bf5e7c93291047dcc0678ece2db754df6df79ab714c94a5e13eabb3e098279ac1fae4e20c043117e37d3356e0f1bc00c5748ff58b0a84c
|
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 paul@denknerd.org. 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/LICENSE.txt
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
2
|
+
Version 2, December 2004
|
3
|
+
|
4
|
+
Copyright (c) 2017 Paul David <paul.david@redbubble.com>
|
5
|
+
and Redbubble, Inc.
|
6
|
+
|
7
|
+
Everyone is permitted to copy and distribute verbatim or modified
|
8
|
+
copies of this license document, and changing it is allowed as long
|
9
|
+
as the name is changed.
|
10
|
+
|
11
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
12
|
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
13
|
+
|
14
|
+
0. You just DO WHAT THE FUCK YOU WANT TO.
|
data/README.md
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
# Bing::Content::Api
|
2
|
+
|
3
|
+
This Gem is intended to be an as-thin-as-possible wrapper around the
|
4
|
+
Bing Ads Content API.
|
5
|
+
|
6
|
+
## Prerequisites
|
7
|
+
|
8
|
+
You'll need a Bing Merchant Center account, as well as an application
|
9
|
+
that you've created using your Microsoft Developer account. This will
|
10
|
+
give you your "application id", "developer token", and "merchant id"
|
11
|
+
which we'll use in the rest of the code.
|
12
|
+
|
13
|
+
This library also expects you to manage your refresh tokens, so you'll
|
14
|
+
be wanting to save them to a local file, S3, or whatever makes sense
|
15
|
+
in your ecosystem.
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
The usual. Add this line to your application's Gemfile:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'bing-content-api'
|
23
|
+
```
|
24
|
+
|
25
|
+
And then execute:
|
26
|
+
|
27
|
+
$ bundle
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
You'll need to get yourself an authentication token, first.
|
32
|
+
Unfortunately, that's a process that requires interactive user
|
33
|
+
intervention. Once you've got a refresh token though, you shouldn't
|
34
|
+
need to worry about manual intervention any more.
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
auth = retrieve_my_saved_token
|
38
|
+
bing_client = Bing::Content::Api::Client.new(APPLICATION_ID,
|
39
|
+
DEVELOPER_TOKEN,
|
40
|
+
MERCHANT_ID_STAGING,
|
41
|
+
refresh_token=auth)
|
42
|
+
```
|
43
|
+
|
44
|
+
Instantiating the `Client` class will automatically fetch a refresh
|
45
|
+
token for you. If you still need to get a token, you'll probably want
|
46
|
+
to do something like the following:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
puts bing_client.generate_user_authorisation_url
|
50
|
+
code = gets.strip
|
51
|
+
bing_client.fetch_token_with_code!(code)
|
52
|
+
```
|
53
|
+
|
54
|
+
Right, we're in business! When you've got the required tokens, you'll
|
55
|
+
probably want to do something like the following. First, create some
|
56
|
+
products:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
def product(n=0)
|
60
|
+
Bing::Content::Api::Product.new(
|
61
|
+
"sticker-#{n}",
|
62
|
+
"Awesome sticker ##{n}",
|
63
|
+
"this is the best sticker in the world ##{n}",
|
64
|
+
6.66,
|
65
|
+
"https://www.your-store.com/people/toothbrush/works/3051759-a-thing?p=sticker&size=small",
|
66
|
+
"https://ih1.your-store.net/image.72080/sticker,375x360.jpg",
|
67
|
+
"US",
|
68
|
+
"en",
|
69
|
+
"in stock")
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
73
|
+
Now, submit it to the store:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
batch = Bing::Content::Api::Batch.new()
|
77
|
+
batch.add_insertions([product(1)])
|
78
|
+
response1 = bing_client.runBatch(batch)
|
79
|
+
```
|
80
|
+
|
81
|
+
Let's see what's in the catalogue:
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
response2 = bing_client.retrieve_catalogue
|
85
|
+
```
|
86
|
+
|
87
|
+
Your catalogue should now contain a product!
|
88
|
+
|
89
|
+
## Development
|
90
|
+
|
91
|
+
After checking out the repo, run `bin/setup` to install
|
92
|
+
dependencies. Then, run `bundle exec rspec` to run the tests. You can
|
93
|
+
also run `bin/console` for an interactive prompt that will allow you
|
94
|
+
to experiment.
|
95
|
+
|
96
|
+
To install this gem onto your local machine, run `bundle exec rake
|
97
|
+
install`. To release a new version, update the version number in
|
98
|
+
`version.rb`, and then run `bundle exec rake release`, which will
|
99
|
+
create a git tag for the version, push git commits and tags, and push
|
100
|
+
the `.gem` file to [rubygems.org](https://rubygems.org).
|
101
|
+
|
102
|
+
## Contributing
|
103
|
+
|
104
|
+
Bug reports and pull requests are welcome on GitHub at
|
105
|
+
https://github.com/redbubble/bing-content-api. This project is
|
106
|
+
intended to be a safe, welcoming space for collaboration, and
|
107
|
+
contributors are expected to adhere to
|
108
|
+
the [Contributor Covenant](http://contributor-covenant.org) code of
|
109
|
+
conduct.
|
110
|
+
|
111
|
+
|
112
|
+
## License
|
113
|
+
|
114
|
+
The gem is available as open source under the terms of
|
115
|
+
the [WTFPL License](http://www.wtfpl.net/).
|
116
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "bing/content/api"
|
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,42 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bing/content/api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bing-content-api"
|
8
|
+
spec.version = Bing::Content::Api::VERSION
|
9
|
+
spec.authors = ["Paul David"]
|
10
|
+
spec.email = ["paul.david@redbubble.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Interface with Bing Content API for managing Shopping Ads.}
|
13
|
+
spec.homepage = "https://github.com/redbubble/bing-content-api"
|
14
|
+
spec.license = "WTFPL"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
"public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
35
|
+
spec.add_development_dependency "vcr", "~> 3.0.3"
|
36
|
+
spec.add_development_dependency "factory_girl", "~> 4.0"
|
37
|
+
spec.add_development_dependency "httpclient", "~> 2.8.3"
|
38
|
+
spec.add_development_dependency "webmock", "~> 3.0.1"
|
39
|
+
|
40
|
+
spec.add_dependency "oauth2", "~> 1.3.1"
|
41
|
+
spec.add_dependency "httpi", "~> 2.4.2"
|
42
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Bing
|
2
|
+
module Content
|
3
|
+
module Api
|
4
|
+
class Batch
|
5
|
+
attr_reader :operations
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@operations = []
|
9
|
+
|
10
|
+
@ids = (1..1000).to_a
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_insertions(products)
|
14
|
+
products.each do |prod|
|
15
|
+
@operations << BatchOperation.new(@ids.pop, prod, :insert)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_deletions(products)
|
20
|
+
products.each do |prod|
|
21
|
+
@operations << BatchOperation.new(@ids.pop, prod, :delete)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def all_products
|
26
|
+
@operations.map { |op| op.product }
|
27
|
+
end
|
28
|
+
|
29
|
+
def product_by_batch_id(id)
|
30
|
+
@operations.select { |op| op.batch_id == id }.first.product
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Bing
|
2
|
+
module Content
|
3
|
+
module Api
|
4
|
+
class BatchOperation
|
5
|
+
|
6
|
+
attr_reader :batch_id
|
7
|
+
attr_reader :product
|
8
|
+
attr_reader :action
|
9
|
+
|
10
|
+
def initialize(batch_id, product, action=:insert)
|
11
|
+
raise "Please select a valid operation." unless [:insert, :delete].include? action
|
12
|
+
|
13
|
+
@batch_id = batch_id
|
14
|
+
@product = product
|
15
|
+
@action = action
|
16
|
+
end
|
17
|
+
|
18
|
+
def bing_operation
|
19
|
+
operation = { batchId: @batch_id }
|
20
|
+
case @action
|
21
|
+
when :insert
|
22
|
+
operation[:product] = @product.to_record
|
23
|
+
operation[:method] = "insert"
|
24
|
+
when :delete
|
25
|
+
operation[:productId] = @product.bing_product_id
|
26
|
+
operation[:method] = "delete"
|
27
|
+
end
|
28
|
+
operation
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Bing
|
2
|
+
module Content
|
3
|
+
module Api
|
4
|
+
class BatchProcessor
|
5
|
+
def initialize(connector)
|
6
|
+
@connector = connector
|
7
|
+
end
|
8
|
+
|
9
|
+
def execute(batch)
|
10
|
+
post_body = to_body(batch)
|
11
|
+
http_response = @connector.post('/products/batch', post_body)
|
12
|
+
body = JSON.parse(http_response.body)
|
13
|
+
entries = body["entries"]
|
14
|
+
|
15
|
+
response = Bing::Content::Api::Response.new
|
16
|
+
response.set_all_products(batch.all_products)
|
17
|
+
|
18
|
+
entries.each do |entry|
|
19
|
+
id = entry["batchId"].to_i
|
20
|
+
response.add_success(batch.product_by_batch_id(id))
|
21
|
+
end
|
22
|
+
|
23
|
+
response
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def to_body(batch)
|
29
|
+
operations = batch.operations.map do |op|
|
30
|
+
op.bing_operation
|
31
|
+
end
|
32
|
+
|
33
|
+
{ entries: operations }.to_json
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'oauth2'
|
2
|
+
|
3
|
+
module Bing
|
4
|
+
module Content
|
5
|
+
module Api
|
6
|
+
class Client
|
7
|
+
attr_accessor :refresh_token_callback
|
8
|
+
attr_reader :refresh_token
|
9
|
+
attr_reader :developer_token
|
10
|
+
|
11
|
+
REDIRECT_URI = "https://login.live.com/oauth20_desktop.srf".freeze
|
12
|
+
|
13
|
+
def initialize(client_id, developer_token, merchant_id, refresh_token=nil, catalogue_id=nil)
|
14
|
+
@client_id = client_id
|
15
|
+
@developer_token = developer_token
|
16
|
+
@merchant_id = merchant_id
|
17
|
+
@refresh_token = refresh_token
|
18
|
+
@catalogue_id = catalogue_id
|
19
|
+
@token = nil
|
20
|
+
@refresh_token_callback = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def generate_user_authorisation_url
|
24
|
+
oauth_client.auth_code.authorize_url(
|
25
|
+
:state => "ArizonaIsAState",
|
26
|
+
:scope => "bingads.manage")
|
27
|
+
end
|
28
|
+
|
29
|
+
def fetch_token_with_code!(verified_url)
|
30
|
+
@token = oauth_client.auth_code.get_token(
|
31
|
+
extract_code(verified_url),
|
32
|
+
:redirect_uri => REDIRECT_URI
|
33
|
+
)
|
34
|
+
self.refresh_token = @token.refresh_token
|
35
|
+
end
|
36
|
+
|
37
|
+
def runBatch(batch)
|
38
|
+
batch_processor = Bing::Content::Api::BatchProcessor.new(connector)
|
39
|
+
batch_processor.execute(batch)
|
40
|
+
end
|
41
|
+
|
42
|
+
def retrieve_catalogue
|
43
|
+
response = connector.get('/products')
|
44
|
+
JSON.parse(response.body)["resources"]
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def refresh_token!
|
50
|
+
@token = OAuth2::AccessToken.new(oauth_client, "")
|
51
|
+
@token.refresh_token = @refresh_token
|
52
|
+
@token = @token.refresh!
|
53
|
+
self.refresh_token = @token.refresh_token
|
54
|
+
end
|
55
|
+
|
56
|
+
def refresh_token=(value)
|
57
|
+
if @refresh_token_callback then
|
58
|
+
@refresh_token_callback.call(value)
|
59
|
+
else
|
60
|
+
puts "WARNING: this is the default refresh_token_callback."
|
61
|
+
puts "You probably want to implement a callback to save your"\
|
62
|
+
" refresh token! Here it is, though:"
|
63
|
+
puts value
|
64
|
+
end
|
65
|
+
@refresh_token = value
|
66
|
+
end
|
67
|
+
|
68
|
+
def extract_code(redirected_url)
|
69
|
+
/code=([0-9a-zA-Z\-]+)&/.match(redirected_url)[1]
|
70
|
+
end
|
71
|
+
|
72
|
+
def connector
|
73
|
+
refresh_token! unless @connector
|
74
|
+
@connector ||= Bing::Content::Api::Connector.new(@developer_token,
|
75
|
+
@token.token,
|
76
|
+
@merchant_id,
|
77
|
+
@catalogue_id)
|
78
|
+
end
|
79
|
+
|
80
|
+
def oauth_client
|
81
|
+
@oauth_client ||= OAuth2::Client.new(@client_id,
|
82
|
+
nil, # client secret isn't applicable for our use
|
83
|
+
:site => 'https://login.live.com',
|
84
|
+
:authorize_url => '/oauth20_authorize.srf',
|
85
|
+
:token_url => '/oauth20_token.srf',
|
86
|
+
:redirect_uri => REDIRECT_URI
|
87
|
+
)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'httpi'
|
2
|
+
|
3
|
+
module Bing
|
4
|
+
module Content
|
5
|
+
module Api
|
6
|
+
class Connector
|
7
|
+
BMC_HOST = "https://su1.content.api.bingads.microsoft.com".freeze
|
8
|
+
|
9
|
+
def initialize(developer_token, token, merchant_id, catalogue_id)
|
10
|
+
@developer_token = developer_token
|
11
|
+
@token = token
|
12
|
+
@merchant_id = merchant_id
|
13
|
+
@catalogue_id = catalogue_id
|
14
|
+
end
|
15
|
+
|
16
|
+
def get(path)
|
17
|
+
request = HTTPI::Request.new
|
18
|
+
request.url = BMC_HOST + base_uri + path
|
19
|
+
request.headers['Content-Type'] = 'application/json'
|
20
|
+
add_auth_headers(request)
|
21
|
+
HTTPI.get(request)
|
22
|
+
end
|
23
|
+
|
24
|
+
def post(path, body)
|
25
|
+
request = HTTPI::Request.new
|
26
|
+
params = { :"bmc-catalog-id" => @catalogue_id } if @catalogue_id
|
27
|
+
url = BMC_HOST + base_uri + path_with_params(path, params)
|
28
|
+
request.url = url
|
29
|
+
request.body = body
|
30
|
+
request.headers['Content-Type'] = 'application/json'
|
31
|
+
add_auth_headers(request)
|
32
|
+
HTTPI.post(request)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def path_with_params(path, params)
|
38
|
+
return path unless params
|
39
|
+
encoded_params = URI.encode_www_form(params)
|
40
|
+
[path, encoded_params].join("?")
|
41
|
+
end
|
42
|
+
|
43
|
+
def add_auth_headers(req)
|
44
|
+
req.headers['DeveloperToken'] = @developer_token
|
45
|
+
req.headers['AuthenticationToken'] = @token
|
46
|
+
end
|
47
|
+
|
48
|
+
def base_uri
|
49
|
+
"/shopping/v9.1/bmc/#{@merchant_id}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Bing
|
2
|
+
module Content
|
3
|
+
module Api
|
4
|
+
class Product
|
5
|
+
attr_reader :offer_id
|
6
|
+
|
7
|
+
def initialize(offer_id,
|
8
|
+
title,
|
9
|
+
description,
|
10
|
+
price,
|
11
|
+
currency,
|
12
|
+
product_link,
|
13
|
+
image_link,
|
14
|
+
target_country="US",
|
15
|
+
content_language="en",
|
16
|
+
availability="in stock",
|
17
|
+
channel="online")
|
18
|
+
@offer_id = offer_id
|
19
|
+
@title = title
|
20
|
+
@description = description
|
21
|
+
@price = price
|
22
|
+
@currency = currency
|
23
|
+
@product_link = product_link
|
24
|
+
@image_link = image_link
|
25
|
+
@target_country = target_country
|
26
|
+
@content_language = content_language
|
27
|
+
@availability = availability
|
28
|
+
@channel = channel
|
29
|
+
end
|
30
|
+
|
31
|
+
def bing_product_id
|
32
|
+
"#{@channel}:#{@content_language}:#{@target_country}:#{@offer_id}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_record
|
36
|
+
{
|
37
|
+
"offerId" => @offer_id,
|
38
|
+
"title" => @title,
|
39
|
+
"description" => @description,
|
40
|
+
"price" => { "currency" => @currency, "value" => @price },
|
41
|
+
"imageLink" => @image_link,
|
42
|
+
"link" => @product_link,
|
43
|
+
"targetCountry" => @target_country,
|
44
|
+
"contentLanguage" => @content_language,
|
45
|
+
"availability" => @availability,
|
46
|
+
"channel" => @channel,
|
47
|
+
"condition" => "new",
|
48
|
+
}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Bing
|
2
|
+
module Content
|
3
|
+
module Api
|
4
|
+
class Response
|
5
|
+
def initialize
|
6
|
+
@successes = []
|
7
|
+
@failures = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_success(product)
|
11
|
+
@failures.delete_if { |prod| prod.offer_id == product.offer_id }
|
12
|
+
@successes << product
|
13
|
+
end
|
14
|
+
|
15
|
+
def set_all_products(products)
|
16
|
+
@failures = products
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require "bing/content/api/version"
|
2
|
+
require "bing/content/api/client"
|
3
|
+
require "bing/content/api/connector"
|
4
|
+
require "bing/content/api/product"
|
5
|
+
require "bing/content/api/batch"
|
6
|
+
require "bing/content/api/response"
|
7
|
+
require "bing/content/api/batch_processor"
|
8
|
+
require "bing/content/api/batch_operation"
|
metadata
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bing-content-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paul David
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: vcr
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.0.3
|
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.3
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: factory_girl
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '4.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '4.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: httpclient
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.8.3
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.8.3
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 3.0.1
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 3.0.1
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: oauth2
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.3.1
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.3.1
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: httpi
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 2.4.2
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 2.4.2
|
139
|
+
description:
|
140
|
+
email:
|
141
|
+
- paul.david@redbubble.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".gitignore"
|
147
|
+
- ".rspec"
|
148
|
+
- ".travis.yml"
|
149
|
+
- CODE_OF_CONDUCT.md
|
150
|
+
- Gemfile
|
151
|
+
- LICENSE.txt
|
152
|
+
- README.md
|
153
|
+
- Rakefile
|
154
|
+
- bin/console
|
155
|
+
- bin/setup
|
156
|
+
- bing-content-api.gemspec
|
157
|
+
- lib/bing/content/api.rb
|
158
|
+
- lib/bing/content/api/batch.rb
|
159
|
+
- lib/bing/content/api/batch_operation.rb
|
160
|
+
- lib/bing/content/api/batch_processor.rb
|
161
|
+
- lib/bing/content/api/client.rb
|
162
|
+
- lib/bing/content/api/connector.rb
|
163
|
+
- lib/bing/content/api/product.rb
|
164
|
+
- lib/bing/content/api/response.rb
|
165
|
+
- lib/bing/content/api/version.rb
|
166
|
+
homepage: https://github.com/redbubble/bing-content-api
|
167
|
+
licenses:
|
168
|
+
- WTFPL
|
169
|
+
metadata:
|
170
|
+
allowed_push_host: https://rubygems.org
|
171
|
+
post_install_message:
|
172
|
+
rdoc_options: []
|
173
|
+
require_paths:
|
174
|
+
- lib
|
175
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - ">="
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
181
|
+
requirements:
|
182
|
+
- - ">="
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
version: '0'
|
185
|
+
requirements: []
|
186
|
+
rubyforge_project:
|
187
|
+
rubygems_version: 2.5.1
|
188
|
+
signing_key:
|
189
|
+
specification_version: 4
|
190
|
+
summary: Interface with Bing Content API for managing Shopping Ads.
|
191
|
+
test_files: []
|