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.



2677
2678
2679
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2677

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

Instance Method Details

#delete_by_organization_id(organization_id) ⇒ Object

Delete the organization with this id



2775
2776
2777
2778
2779
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2775

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

#delete_settings_and_regions_by_organization_id_and_region(organization_id, region) ⇒ Object

Removes the setting for this region for a specific organization



2813
2814
2815
2816
2817
2818
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2813

def delete_settings_and_regions_by_organization_id_and_region(organization_id, region)
  HttpClient::Preconditions.assert_class('organization_id', organization_id, String)
  HttpClient::Preconditions.assert_class('region', region, String)
  r = @client.request("/organizations/#{CGI.escape(organization_id)}/settings/regions/#{CGI.escape(region)}").delete
  nil
end

#get(incoming = {}) ⇒ Object

Search organizations. Always paginated.



2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2721

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) }),
    :channel_id => (x = opts.delete(:channel_id); x.nil? ? nil : HttpClient::Preconditions.assert_class('channel_id', x, 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)),
    :in_channel => (x = opts.delete(:in_channel); x.nil? ? nil : HttpClient::Preconditions.assert_boolean('in_channel', x)),
    :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_organization_id(organization_id) ⇒ Object

Returns information about a specific organization.



2760
2761
2762
2763
2764
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2760

def get_by_organization_id(organization_id)
  HttpClient::Preconditions.assert_class('organization_id', organization_id, String)
  r = @client.request("/organizations/#{CGI.escape(organization_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.



2699
2700
2701
2702
2703
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2699

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_and_statuses_by_organization(organization) ⇒ Object

Status of all countries



2706
2707
2708
2709
2710
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2706

def get_countries_and_statuses_by_organization(organization)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  r = @client.request("/#{CGI.escape(organization)}/countries/statuses").get
  r.map { |x| ::Io::Flow::V0::Models::CountryStatus.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.



2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2684

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)),
    :status => HttpClient::Preconditions.assert_class('status', (x = opts.delete(:status); x.nil? ? [] : x), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::ExperienceStatus) ? x : ::Io::Flow::V0::Models::ExperienceStatus.apply(x)).value },
    :context => (x = opts.delete(:context); x.nil? ? nil : HttpClient::Preconditions.assert_class('context', 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.



2782
2783
2784
2785
2786
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2782

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_settings_and_regions_and_countries_and_available_by_organization_id(organization_id) ⇒ Object

Returns the list of enabled countries based on the region settings for a specific organization



2797
2798
2799
2800
2801
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2797

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

#get_settings_and_regions_by_organization_id(organization_id) ⇒ Object

Returns the region settings associated to a specific organization.



2789
2790
2791
2792
2793
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2789

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

#get_versions(incoming = {}) ⇒ Object

Provides visibility into recent changes of each object, including deletion



2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2746

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.



2739
2740
2741
2742
2743
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2739

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_organization_id(organization_id, organization_put_form) ⇒ Object

Update or create an organization with the specified id.



2767
2768
2769
2770
2771
2772
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2767

def put_by_organization_id(organization_id, organization_put_form)
  HttpClient::Preconditions.assert_class('organization_id', organization_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(organization_id)}").with_json(organization_put_form.to_json).put
  ::Io::Flow::V0::Models::Organization.new(r)
end

#put_countries_and_statuses_by_organization_and_country(organization, country, country_status_form) ⇒ Object



2712
2713
2714
2715
2716
2717
2718
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2712

def put_countries_and_statuses_by_organization_and_country(organization, country, country_status_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('country', country, String)
  (x = country_status_form; x.is_a?(::Io::Flow::V0::Models::CountryStatusForm) ? x : ::Io::Flow::V0::Models::CountryStatusForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/countries/statuses/#{CGI.escape(country)}").with_json(country_status_form.to_json).put
  ::Io::Flow::V0::Models::CountryStatus.new(r)
end

#put_settings_and_regions_by_organization_id_and_region(organization_id, region, region_setting_form) ⇒ Object

Updates or creates a region setting for a specific organization



2804
2805
2806
2807
2808
2809
2810
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2804

def put_settings_and_regions_by_organization_id_and_region(organization_id, region, region_setting_form)
  HttpClient::Preconditions.assert_class('organization_id', organization_id, String)
  HttpClient::Preconditions.assert_class('region', region, String)
  (x = region_setting_form; x.is_a?(::Io::Flow::V0::Models::RegionSettingForm) ? x : ::Io::Flow::V0::Models::RegionSettingForm.new(x))
  r = @client.request("/organizations/#{CGI.escape(organization_id)}/settings/regions/#{CGI.escape(region)}").with_json(region_setting_form.to_json).put
  ::Io::Flow::V0::Models::RegionSetting.new(r)
end