Class: Io::Flow::V0::Clients::Experiences

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Experiences

Returns a new instance of Experiences.



648
649
650
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 648

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

Instance Method Details

#delete_by_key(organization, key) ⇒ Object

Delete the experience with this key



796
797
798
799
800
801
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 796

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

#delete_margins_by_experience_key_and_key(organization, experience_key, key) ⇒ Object



719
720
721
722
723
724
725
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 719

def delete_margins_by_experience_key_and_key(organization, experience_key, key)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('experience_key', experience_key, String)
  HttpClient::Preconditions.assert_class('key', key, String)
  r = @client.request("/#{CGI.escape(organization)}/experiences/#{CGI.escape(experience_key)}/margins/#{CGI.escape(key)}").delete
  nil
end

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

Search experiences. Always paginated.



653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 653

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) }),
    :name => (x = opts.delete(:name); x.nil? ? nil : HttpClient::Preconditions.assert_class('name', x, String)),
    :region => (x = opts.delete(:region); x.nil? ? nil : HttpClient::Preconditions.assert_class('region', x, String)),
    :currency => (x = opts.delete(:currency); x.nil? ? nil : HttpClient::Preconditions.assert_class('currency', x, String)),
    :subcatalog => (x = opts.delete(:subcatalog); x.nil? ? nil : HttpClient::Preconditions.assert_class('subcatalog', x, String)),
    :ip => (x = opts.delete(:ip); x.nil? ? nil : HttpClient::Preconditions.assert_class('ip', 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("/#{CGI.escape(organization)}/experiences").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::Experience.new(x) }
end

#get_by_key(organization, key) ⇒ Object

Returns information about a specific experience.



779
780
781
782
783
784
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 779

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

#get_conversions_by_base_and_amount(organization, base, amount, incoming = {}) ⇒ Object

Formats the requested amount using the formatting settings for the experience.



840
841
842
843
844
845
846
847
848
849
850
851
852
853
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 840

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

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

Returns localized information about 1 or more items. The items will be localized based on the experience selected by the query parameters in the order of experience, then country, then ip address.



858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 858

def get_items(organization, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :number => (x = opts.delete(:number); x.nil? ? nil : HttpClient::Preconditions.assert_class('number', x, Array).map { |v| HttpClient::Preconditions.assert_class('number', v, String) }),
    :status => (x = opts.delete(:status); x.nil? ? nil : HttpClient::Preconditions.assert_class('status', x, Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::SubcatalogItemStatus) ? x : ::Io::Flow::V0::Models::SubcatalogItemStatus.apply(x)).value }),
    :experience => (x = opts.delete(:experience); x.nil? ? nil : HttpClient::Preconditions.assert_class('experience', x, String)),
    :country => (x = opts.delete(:country); x.nil? ? nil : HttpClient::Preconditions.assert_class('country', x, String)),
    :ip => (x = opts.delete(:ip); x.nil? ? nil : HttpClient::Preconditions.assert_class('ip', x, String)),
    :currency => (x = opts.delete(:currency); x.nil? ? nil : HttpClient::Preconditions.assert_class('currency', x, String)),
    :language => (x = opts.delete(:language); x.nil? ? nil : HttpClient::Preconditions.assert_class('language', 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? ? "-created_at" : x), String)
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/#{CGI.escape(organization)}/experiences/items").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::Item.new(x) }
end

#get_items_and_price_by_key_and_number(organization, key, number) ⇒ Object

Returns detailed information on the pricing of this item within this experience



805
806
807
808
809
810
811
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 805

def get_items_and_price_by_key_and_number(organization, key, number)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('key', key, String)
  HttpClient::Preconditions.assert_class('number', number, String)
  r = @client.request("/#{CGI.escape(organization)}/experiences/#{CGI.escape(key)}/items/#{CGI.escape(number)}/price").get
  ::Io::Flow::V0::Models::PriceCheck.new(r)
end

#get_items_by_number(organization, number, incoming = {}) ⇒ Object

Returns information about this item localized based on the query parameters



878
879
880
881
882
883
884
885
886
887
888
889
890
891
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 878

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

#get_margins_and_versions_by_experience_key(organization, experience_key, incoming = {}) ⇒ Object



727
728
729
730
731
732
733
734
735
736
737
738
739
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 727

def get_margins_and_versions_by_experience_key(organization, experience_key, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('experience_key', experience_key, 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) }),
    :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("/#{CGI.escape(organization)}/experiences/#{CGI.escape(experience_key)}/margins/versions").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::ItemMarginVersion.new(x) }
end

#get_margins_by_experience_key(organization, experience_key, incoming = {}) ⇒ Object



680
681
682
683
684
685
686
687
688
689
690
691
692
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 680

def get_margins_by_experience_key(organization, experience_key, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('experience_key', experience_key, 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) }),
    :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("/#{CGI.escape(organization)}/experiences/#{CGI.escape(experience_key)}/margins").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::ItemMargin.new(x) }
end

#get_margins_by_experience_key_and_key(organization, experience_key, key) ⇒ Object



702
703
704
705
706
707
708
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 702

def get_margins_by_experience_key_and_key(organization, experience_key, key)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('experience_key', experience_key, String)
  HttpClient::Preconditions.assert_class('key', key, String)
  r = @client.request("/#{CGI.escape(organization)}/experiences/#{CGI.escape(experience_key)}/margins/#{CGI.escape(key)}").get
  ::Io::Flow::V0::Models::ItemMargin.new(r)
end

#get_payment_and_method_and_rules_by_experience_key(organization, experience_key, incoming = {}) ⇒ Object



753
754
755
756
757
758
759
760
761
762
763
764
765
766
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 753

def get_payment_and_method_and_rules_by_experience_key(organization, experience_key, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('experience_key', experience_key, String)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :payment_method_type => (x = opts.delete(:payment_method_type); x.nil? ? nil : HttpClient::Preconditions.assert_class('payment_method_type', x, Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::PaymentMethodType) ? x : ::Io::Flow::V0::Models::PaymentMethodType.apply(x)).value }),
    :tags => (x = opts.delete(:tags); x.nil? ? nil : HttpClient::Preconditions.assert_class('tags', x, Array).map { |v| HttpClient::Preconditions.assert_class('tags', 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? ? "display_position" : x), String)
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/#{CGI.escape(organization)}/experiences/#{CGI.escape(experience_key)}/payment/method/rules").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::PaymentMethodRule.new(x) }
end

#get_payment_method_types_by_experience_key(organization, experience_key, incoming = {}) ⇒ Object



741
742
743
744
745
746
747
748
749
750
751
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 741

def get_payment_method_types_by_experience_key(organization, experience_key, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('experience_key', experience_key, String)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :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)
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/#{CGI.escape(organization)}/experiences/#{CGI.escape(experience_key)}/payment-method-types").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::PaymentMethodType.new(x) }
end

#get_pricing_by_key(organization, key) ⇒ Object

Get the pricing settings for this experience



814
815
816
817
818
819
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 814

def get_pricing_by_key(organization, key)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('key', key, String)
  r = @client.request("/#{CGI.escape(organization)}/experiences/#{CGI.escape(key)}/pricing").get
  ::Io::Flow::V0::Models::Pricing.new(r)
end

#get_promotions_and_available_by_key(organization, key) ⇒ Object

Get available promotions for the experience



831
832
833
834
835
836
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 831

def get_promotions_and_available_by_key(organization, key)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('key', key, String)
  r = @client.request("/#{CGI.escape(organization)}/experiences/#{CGI.escape(key)}/promotions/available").get
  r.map { |x| ::Io::Flow::V0::Models::Promotion.from_json(x) }
end

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

Provides visibility into recent changes of each object, including deletion



894
895
896
897
898
899
900
901
902
903
904
905
906
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 894

def get_versions(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? ? "journal_timestamp" : x), String)
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/#{CGI.escape(organization)}/experiences/versions").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::ExperienceVersion.new(x) }
end

#post(organization, experience_form) ⇒ Object

Add experience



673
674
675
676
677
678
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 673

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

#post_margins_by_experience_key(organization, experience_key, item_margin_post_form) ⇒ Object



694
695
696
697
698
699
700
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 694

def post_margins_by_experience_key(organization, experience_key, item_margin_post_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('experience_key', experience_key, String)
  (x = item_margin_post_form; x.is_a?(::Io::Flow::V0::Models::ItemMarginPostForm) ? x : ::Io::Flow::V0::Models::ItemMarginPostForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/experiences/#{CGI.escape(experience_key)}/margins").with_json(item_margin_post_form.to_json).post
  ::Io::Flow::V0::Models::ItemMargin.new(r)
end

#put_by_key(organization, key, experience_form) ⇒ Object

Update experience with the specified key, creating if it does not exist.



787
788
789
790
791
792
793
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 787

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

#put_margins_by_experience_key_and_key(organization, experience_key, key, item_margin_put_form) ⇒ Object



710
711
712
713
714
715
716
717
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 710

def put_margins_by_experience_key_and_key(organization, experience_key, key, item_margin_put_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('experience_key', experience_key, String)
  HttpClient::Preconditions.assert_class('key', key, String)
  (x = item_margin_put_form; x.is_a?(::Io::Flow::V0::Models::ItemMarginPutForm) ? x : ::Io::Flow::V0::Models::ItemMarginPutForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/experiences/#{CGI.escape(experience_key)}/margins/#{CGI.escape(key)}").with_json(item_margin_put_form.to_json).put
  ::Io::Flow::V0::Models::ItemMargin.new(r)
end

#put_payment_and_method_and_rules_by_experience_key(organization, experience_key, experience_payment_method_rule_forms) ⇒ Object

Change the ordering or payment tags for an experience. Every post must include one entry for each payment method offered by Flow.



770
771
772
773
774
775
776
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 770

def put_payment_and_method_and_rules_by_experience_key(organization, experience_key, experience_payment_method_rule_forms)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('experience_key', experience_key, String)
  HttpClient::Preconditions.assert_class('experience_payment_method_rule_forms', experience_payment_method_rule_forms, Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::ExperiencePaymentMethodRuleForm) ? x : ::Io::Flow::V0::Models::ExperiencePaymentMethodRuleForm.new(x)) }
  r = @client.request("/#{CGI.escape(organization)}/experiences/#{CGI.escape(experience_key)}/payment/method/rules").with_json(experience_payment_method_rule_forms.map { |o| o.to_hash }.to_json).put
  r.map { |x| ::Io::Flow::V0::Models::PaymentMethodRule.new(x) }
end

#put_pricing_by_key(organization, key, pricing) ⇒ Object

Update the pricing settings for this experience



822
823
824
825
826
827
828
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 822

def put_pricing_by_key(organization, key, pricing)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('key', key, String)
  (x = pricing; x.is_a?(::Io::Flow::V0::Models::Pricing) ? x : ::Io::Flow::V0::Models::Pricing.new(x))
  r = @client.request("/#{CGI.escape(organization)}/experiences/#{CGI.escape(key)}/pricing").with_json(pricing.to_json).put
  ::Io::Flow::V0::Models::Pricing.new(r)
end