lib/search_spring/client.rb in search_spring-0.2.1 vs lib/search_spring/client.rb in search_spring-0.2.5
- old
+ new
@@ -1,11 +1,9 @@
require_relative 'errors'
module SearchSpring
API_ENDPOINT = 'https://api.searchspring.net'.freeze
- #
- #
class Client
attr_reader :site_id, :conn, :secret_key
def initialize(site_id, secret_key, req_options = {})
@site_id = site_id
@@ -17,42 +15,51 @@
@conn = connection(req_options)
end
def upsert(feed_id:, products: [])
- conn.post(
- 'api/index/upsert.json',
- feedId: feed_id,
- records: products
- )
+ conn.post do |req|
+ req.url 'api/index/upsert.json'
+ req.headers['Content-Type'] = 'application/json'
+ req.body = MultiJson.dump(
+ feedId: feed_id,
+ records: products
+ )
+ end
end
def update(feed_id:, products: [])
- conn.post(
- 'api/index/update.json',
- feedId: feed_id,
- records: products
- )
+ conn.post do |req|
+ req.url 'api/index/update.json'
+ req.headers['Content-Type'] = 'application/json'
+ req.body = MultiJson.dump(
+ feedId: feed_id,
+ records: products
+ )
+ end
end
def delete(feed_id:, product_ids: [])
- conn.post(
- 'api/index/delete.json',
- feedId: feed_id,
- records: product_ids
- )
+ conn.post do |req|
+ req.url 'api/index/delete.json'
+ req.headers['Content-Type'] = 'application/json'
+ req.body = MultiJson.dump(
+ feedId: feed_id,
+ records: product_ids
+ )
+ end
end
private
def connection(options = {})
Faraday.new(default_req_options.merge(options)) do |f|
+ f.request :url_encoded
f.headers['Accept'] = 'application/json'
- f.request :json
f.request :basic_auth, site_id, secret_key
f.response :logger
- f.adapter :excon
f.use Errors::RequestError
+ f.adapter :excon
end
end
def default_req_options
{