Class: Io::Flow::V0::Clients::SyncStreams

Inherits:
Object
  • Object
show all
Defined in:
lib/flow_commerce/flow_api_v0_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ SyncStreams

Returns a new instance of SyncStreams.



7555
7556
7557
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7555

def initialize(client)
  @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::V0::Client)
end

Instance Method Details

#delete_by_key(organization, key) ⇒ Object



7596
7597
7598
7599
7600
7601
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7596

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)}/sync/streams/#{CGI.escape(key)}").delete
  nil
end

#get(organization, incoming = {}) ⇒ Object



7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7559

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, String)),
    :type => (x = opts.delete(:type); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::SyncStreamType) ? x : ::Io::Flow::V0::Models::SyncStreamType.apply(x)).value),
    :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)}/sync/streams").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::SyncStream.new(x) }
end

#get_by_key(organization, key) ⇒ Object



7581
7582
7583
7584
7585
7586
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7581

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)}/sync/streams/#{CGI.escape(key)}").get
  ::Io::Flow::V0::Models::SyncStream.new(r)
end

#post(organization, sync_stream_form) ⇒ Object



7574
7575
7576
7577
7578
7579
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7574

def post(organization, sync_stream_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  (x = sync_stream_form; x.is_a?(::Io::Flow::V0::Models::SyncStreamForm) ? x : ::Io::Flow::V0::Models::SyncStreamForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/sync/streams").with_json(sync_stream_form.to_json).post
  ::Io::Flow::V0::Models::SyncStream.new(r)
end

#put_by_key(organization, key, sync_stream_form) ⇒ Object



7588
7589
7590
7591
7592
7593
7594
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7588

def put_by_key(organization, key, sync_stream_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('key', key, String)
  (x = sync_stream_form; x.is_a?(::Io::Flow::V0::Models::SyncStreamForm) ? x : ::Io::Flow::V0::Models::SyncStreamForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/sync/streams/#{CGI.escape(key)}").with_json(sync_stream_form.to_json).put
  ::Io::Flow::V0::Models::SyncStream.new(r)
end