Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/seoshop-api/api/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Seoshop
module Catalog
def get_catalog(catalog_id = nil)
response = catalog_id.nil? ? get("#{@shop_language}/catalog.json") : get("#{@shop_language}/catalog/#{catalog_id}.json")
response.body ? response.body['products'] : false
response.body ? response.body[catalog_id.nil? ? 'products' : 'product'] : false
end

def get_catalog_count
Expand Down
33 changes: 33 additions & 0 deletions lib/seoshop-api/api/webhook.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module Seoshop
module Webhook
def get_webhooks_count(params = {})
response = get("#{@shop_language}/webhooks/count.json", params)
response.body ? response.body['count'].to_i : 0
end

def get_webhooks(params = {})
response = get("#{@shop_language}/webhooks.json", params)
response.body ? response.body['webhooks'] || [] : []
end

def create_webhook(params, options = {})
response = post("#{@shop_language}/webhooks.json", { "webhook" => params })
response.status == 201
end

def update_webhook(id, params)
response = put("#{@shop_language}/webhooks/#{id}.json", { "webhook" => params } )
response.body ? response.body['webhook'] : {}
end

def get_webhook(id)
response = get("#{@shop_language}/webhooks/#{id}.json")
response.body ? response.body['webhook'] : nil
end

def delete_webhook(id)
response = delete("#{@shop_language}/webhooks/#{id}.json")
true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

response.status == 204

end
end
end
2 changes: 2 additions & 0 deletions lib/seoshop-api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
require 'seoshop-api/api/shop_script'
require 'seoshop-api/api/shop_tracking'
require 'seoshop-api/api/catalog'
require 'seoshop-api/api/webhook'
require 'seoshop-api/fetch_resource_helper'

module Seoshop
Expand All @@ -32,6 +33,7 @@ class Client
include Seoshop::Tax
include Seoshop::Catalog
include Seoshop::FetchResourceHelper
include Seoshop::Webhook

attr_accessor :api_key
attr_accessor :api_secret
Expand Down
2 changes: 2 additions & 0 deletions lib/seoshop-api/core/response_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def call(env)
body = false
if env[:status] == 200
body = env[:response].body.response || env[:response].body
elsif env[:status] == 204
body = env[:response].body
elsif env[:status] == 401
raise Seoshop::ResponseParser::HTTPUnauthorized.new 'invalid Seoshop credentials'
elsif env[:status] == 403
Expand Down