Class: Io::Flow::V0::Clients::Organizations

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Organizations

Returns a new instance of Organizations.



1224
1225
1226
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1224

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

Instance Method Details

#delete_by_id(id) ⇒ Object

Delete the organization with this id



1289
1290
1291
1292
1293
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1289

def delete_by_id(id)
  HttpClient::Preconditions.assert_class('id', id, String)
  r = @client.request("/organizations/#{CGI.escape(id)}").delete
  nil
end

#get(incoming = {}) ⇒ Object

Search organizations. Always paginated.



1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1251

def get(incoming={})
  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) }),
    :name => (x = opts.delete(:name); x.nil? ? nil : HttpClient::Preconditions.assert_class('name', x, String)),
    :environment => (x = opts.delete(:environment); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::Environment) ? x : ::Io::Flow::V0::Models::Environment.apply(x)).value),
    :parent => (x = opts.delete(:parent); x.nil? ? nil : HttpClient::Preconditions.assert_class('parent', x, 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? ? "name" : x), String)
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/organizations").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::Organization.new(x) }
end

#get_by_id(id) ⇒ Object

Returns information about a specific organization.



1274
1275
1276
1277
1278
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1274

def get_by_id(id)
  HttpClient::Preconditions.assert_class('id', id, String)
  r = @client.request("/organizations/#{CGI.escape(id)}").get
  ::Io::Flow::V0::Models::Organization.new(r)
end

#get_countries_and_destinations_by_organization(organization) ⇒ Object

List of all destination countries available for this organization, including countries within a world experience.



1244
1245
1246
1247
1248
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1244

def get_countries_and_destinations_by_organization(organization)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  r = @client.request("/#{CGI.escape(organization)}/countries/destinations").get
  r.map { |x| ::Io::Flow::V0::Models::Country.new(x) }
end

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

The countries resources provides a unique list of all of the countries for which an experience exists. We generate this list of countries by iterating through all of the experience regions, and collecting all of the countries.



1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1231

def get_countries_by_organization(organization, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :ip => (x = opts.delete(:ip); x.nil? ? nil : HttpClient::Preconditions.assert_class('ip', x, String)),
    :country => (x = opts.delete(:country); x.nil? ? nil : HttpClient::Preconditions.assert_class('country', x, String))
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/#{CGI.escape(organization)}/countries").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::Country.new(x) }
end

#get_settings_and_currencies_by_organization_id(organization_id) ⇒ Object

Returns currencies for a specific organization.



1296
1297
1298
1299
1300
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1296

def get_settings_and_currencies_by_organization_id(organization_id)
  HttpClient::Preconditions.assert_class('organization_id', organization_id, String)
  r = @client.request("/organizations/#{CGI.escape(organization_id)}/settings/currencies").get
  r.map { |x| ::Io::Flow::V0::Models::Currency.new(x) }
end

#get_versions(incoming = {}) ⇒ Object

Provides visibility into recent changes of each object, including deletion



1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1303

def get_versions(incoming={})
  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) }),
    :organization => (x = opts.delete(:organization); x.nil? ? nil : HttpClient::Preconditions.assert_class('organization', x, Array).map { |v| HttpClient::Preconditions.assert_class('organization', 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? ? "journal_timestamp" : x), String)
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/organizations/versions").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::OrganizationVersion.new(x) }
end

#post(organization_form) ⇒ Object

Create a new organization.



1267
1268
1269
1270
1271
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1267

def post(organization_form)
  (x = organization_form; x.is_a?(::Io::Flow::V0::Models::OrganizationForm) ? x : ::Io::Flow::V0::Models::OrganizationForm.new(x))
  r = @client.request("/organizations").with_json(organization_form.to_json).post
  ::Io::Flow::V0::Models::Organization.new(r)
end

#put_by_id(id, organization_put_form) ⇒ Object

Update or create an organization with the specified id.



1281
1282
1283
1284
1285
1286
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1281

def put_by_id(id, organization_put_form)
  HttpClient::Preconditions.assert_class('id', id, String)
  (x = organization_put_form; x.is_a?(::Io::Flow::V0::Models::OrganizationPutForm) ? x : ::Io::Flow::V0::Models::OrganizationPutForm.new(x))
  r = @client.request("/organizations/#{CGI.escape(id)}").with_json(organization_put_form.to_json).put
  ::Io::Flow::V0::Models::Organization.new(r)
end