Class: Io::Flow::V0::Clients::PriceBooks
- Inherits:
-
Object
- Object
- Io::Flow::V0::Clients::PriceBooks
- Defined in:
- lib/flow_commerce/flow_api_v0_client.rb
Instance Method Summary collapse
-
#delete_by_key(organization, key) ⇒ Object
Deletes the specified price book.
- #get(organization, incoming = {}) ⇒ Object
-
#get_by_key(organization, key) ⇒ Object
Returns information about a specific price book.
-
#initialize(client) ⇒ PriceBooks
constructor
A new instance of PriceBooks.
-
#post(organization, price_book_form) ⇒ Object
Create a price book.
-
#put_by_key(organization, key, price_book_form) ⇒ Object
Create or update a price book.
Constructor Details
#initialize(client) ⇒ PriceBooks
Returns a new instance of PriceBooks.
2882 2883 2884 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2882 def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::V0::Client) end |
Instance Method Details
#delete_by_key(organization, key) ⇒ Object
Deletes the specified price book
2926 2927 2928 2929 2930 2931 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2926 def delete_by_key(organization, key) HttpClient::Preconditions.assert_class('organization', organization, String) HttpClient::Preconditions.assert_class('key', key, String) r = @client.request("/#{CGI.escape(organization)}/price/books/#{CGI.escape(key)}").delete nil end |
#get(organization, incoming = {}) ⇒ Object
2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2886 def get(organization, incoming={}) HttpClient::Preconditions.assert_class('organization', organization, String) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, String) }), :key => (x = opts.delete(:key); x.nil? ? nil : HttpClient::Preconditions.assert_class('key', x, Array).map { |v| HttpClient::Preconditions.assert_class('key', v, String) }), :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer), :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer), :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "-created_at" : x), String) }.delete_if { |k, v| v.nil? } r = @client.request("/#{CGI.escape(organization)}/price/books").with_query(query).get r.map { |x| ::Io::Flow::V0::Models::PriceBook.new(x) } end |
#get_by_key(organization, key) ⇒ Object
Returns information about a specific price book.
2909 2910 2911 2912 2913 2914 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2909 def get_by_key(organization, key) HttpClient::Preconditions.assert_class('organization', organization, String) HttpClient::Preconditions.assert_class('key', key, String) r = @client.request("/#{CGI.escape(organization)}/price/books/#{CGI.escape(key)}").get ::Io::Flow::V0::Models::PriceBook.new(r) end |
#post(organization, price_book_form) ⇒ Object
Create a price book.
2901 2902 2903 2904 2905 2906 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2901 def post(organization, price_book_form) HttpClient::Preconditions.assert_class('organization', organization, String) (x = price_book_form; x.is_a?(::Io::Flow::V0::Models::PriceBookForm) ? x : ::Io::Flow::V0::Models::PriceBookForm.new(x)) r = @client.request("/#{CGI.escape(organization)}/price/books").with_json(price_book_form.to_json).post ::Io::Flow::V0::Models::PriceBook.new(r) end |
#put_by_key(organization, key, price_book_form) ⇒ Object
Create or update a price book.
2917 2918 2919 2920 2921 2922 2923 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2917 def put_by_key(organization, key, price_book_form) HttpClient::Preconditions.assert_class('organization', organization, String) HttpClient::Preconditions.assert_class('key', key, String) (x = price_book_form; x.is_a?(::Io::Flow::V0::Models::PriceBookForm) ? x : ::Io::Flow::V0::Models::PriceBookForm.new(x)) r = @client.request("/#{CGI.escape(organization)}/price/books/#{CGI.escape(key)}").with_json(price_book_form.to_json).put ::Io::Flow::V0::Models::PriceBook.new(r) end |