Class: ProoflinkConnect::Invite

Inherits:
Object
  • Object
show all
Defined in:
lib/prooflink_connect/invite.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes, configuration = ProoflinkConnect.config) ⇒ Invite

Returns a new instance of Invite.



10
11
12
13
# File 'lib/prooflink_connect/invite.rb', line 10

def initialize(attributes, configuration = ProoflinkConnect.config)
  @attributes = attributes.stringify_keys
  @configuration = configuration
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



7
8
9
# File 'lib/prooflink_connect/invite.rb', line 7

def attributes
  @attributes
end

#configurationObject (readonly)

Returns the value of attribute configuration.



7
8
9
# File 'lib/prooflink_connect/invite.rb', line 7

def configuration
  @configuration
end

#localeObject

Returns the value of attribute locale.



8
9
10
# File 'lib/prooflink_connect/invite.rb', line 8

def locale
  @locale
end

Instance Method Details

#personObject



34
35
36
# File 'lib/prooflink_connect/invite.rb', line 34

def person
  @person ||= ProoflinkConnect::PortableContacts::Person.new(attributes)
end

#save(params = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/prooflink_connect/invite.rb', line 15

def save(params = {})
  return false if created?

  uri = configuration.base_uri + "/invites"
  params.reverse_merge! "invite" => attributes, "api_key" =>  configuration.api_key, "locale" => locale || 'nl'

  response = HTTParty.post(uri, :body => params)

  if response.code == 200
    self.attributes.merge! MultiJson.load(response.body)["entry"].stringify_keys
  end

  return created?
end

#urlObject



30
31
32
# File 'lib/prooflink_connect/invite.rb', line 30

def url
  attributes["invite_url"] if created?
end