Class: Io::Flow::V0::Clients::Invitations

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Invitations

Returns a new instance of Invitations.



3866
3867
3868
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3866

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

Instance Method Details

#delete_by_id(id) ⇒ Object



3905
3906
3907
3908
3909
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3905

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

#get(incoming = {}) ⇒ Object

Search invitations. Always paginated.



3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3871

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

#get_by_id(id, incoming = {}) ⇒ Object

Returns information about a specific invitation.



3895
3896
3897
3898
3899
3900
3901
3902
3903
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3895

def get_by_id(id, incoming={})
  HttpClient::Preconditions.assert_class('id', id, String)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :expand => (x = opts.delete(:expand); x.nil? ? nil : HttpClient::Preconditions.assert_class('expand', x, Array).map { |v| HttpClient::Preconditions.assert_class('expand', v, String) })
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/invitations/#{CGI.escape(id)}").with_query(query).get
  ::Io::Flow::V0::Models::Invitation.new(r)
end

#get_tokens_by_token(token, incoming = {}) ⇒ Object

Lookup an invitation by its token.



3912
3913
3914
3915
3916
3917
3918
3919
3920
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3912

def get_tokens_by_token(token, incoming={})
  HttpClient::Preconditions.assert_class('token', token, String)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :expand => (x = opts.delete(:expand); x.nil? ? nil : HttpClient::Preconditions.assert_class('expand', x, Array).map { |v| HttpClient::Preconditions.assert_class('expand', v, String) })
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/invitations/tokens/#{CGI.escape(token)}").with_query(query).get
  ::Io::Flow::V0::Models::Invitation.new(r)
end

#get_versions(incoming = {}) ⇒ Object



3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3934

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) }),
    :invitation => (x = opts.delete(:invitation); x.nil? ? nil : HttpClient::Preconditions.assert_class('invitation', x, Array).map { |v| HttpClient::Preconditions.assert_class('invitation', 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("/invitations/versions").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::InvitationVersion.new(x) }
end

#post(invitation_form) ⇒ Object

Create a new invitation.



3888
3889
3890
3891
3892
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3888

def post(invitation_form)
  (x = invitation_form; x.is_a?(::Io::Flow::V0::Models::InvitationForm) ? x : ::Io::Flow::V0::Models::InvitationForm.new(x))
  r = @client.request("/invitations").with_json(invitation_form.to_json).post
  ::Io::Flow::V0::Models::Invitation.new(r)
end

#put_tokens_by_token(token, hash) ⇒ Object

Accepts the invitation w/ the specified token and the authenticated user. Creating a membership record for this user within this organization. Invitations are one time use only - you will get a validation error if the invitation has previously been accepted or if the user’s email addresses do not match the email on the invite.



3927
3928
3929
3930
3931
3932
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3927

def put_tokens_by_token(token, hash)
  HttpClient::Preconditions.assert_class('token', token, String)
  HttpClient::Preconditions.assert_class('hash', hash, Hash)
  r = @client.request("/invitations/tokens/#{CGI.escape(token)}").with_json(hash.to_json).put
  ::Io::Flow::V0::Models::Membership.new(r)
end