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.



629
630
631
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 629

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



777
778
779
780
781
782
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 777

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



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

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.



634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 634

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.



760
761
762
763
764
765
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 760

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.



821
822
823
824
825
826
827
828
829
830
831
832
833
834
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 821

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.



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

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



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

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



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

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



708
709
710
711
712
713
714
715
716
717
718
719
720
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 708

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



661
662
663
664
665
666
667
668
669
670
671
672
673
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 661

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



683
684
685
686
687
688
689
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 683

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_method_rules_by_experience_key(organization, experience_key, incoming = {}) ⇒ Object



722
723
724
725
726
727
728
729
730
731
732
733
734
735
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 722

def get_payment_method_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



747
748
749
750
751
752
753
754
755
756
757
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 747

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



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

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



812
813
814
815
816
817
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 812

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



875
876
877
878
879
880
881
882
883
884
885
886
887
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 875

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



654
655
656
657
658
659
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 654

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



675
676
677
678
679
680
681
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 675

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.



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

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



691
692
693
694
695
696
697
698
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 691

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_method_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.



739
740
741
742
743
744
745
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 739

def put_payment_method_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



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

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