Class: PortaText::Command::Api::Contacts

Inherits:
Base
  • Object
show all
Defined in:
lib/portatext/command/api/contacts.rb

Overview

The contacts endpoint. github.com/PortaText/docs/wiki/REST-API#api_all_contacts

Author

Marcelo Gornstein ([email protected])

Copyright

Copyright © 2015 PortaText

License

Apache-2.0

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#accept_content_type, #body, #content_type, #delete, #get, #initialize, #patch, #post, #put, #set

Constructor Details

This class inherits a constructor from PortaText::Command::Base

Instance Method Details

#csv(file) ⇒ Object



32
33
34
# File 'lib/portatext/command/api/contacts.rb', line 32

def csv(file)
  set :file, file
end

#endpoint(_method) ⇒ Object

rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/portatext/command/api/contacts.rb', line 51

def endpoint(_method)
  qs = {}
  unless @args[:page].nil?
    qs['page'] = @args[:page]
    @args.delete :page
  end
  unless @args[:with_contact_lists].nil?
    qs['with_contact_lists'] = 'true'
    @args.delete :with_contact_lists
  end
  qs = URI.encode_www_form qs
  return "contacts?#{qs}" if @args[:number].nil?
  number = @args[:number]
  @args.delete :number
  return "contacts/#{number}/variables" if @args[:name].nil?
  name = @args[:name]
  @args.delete :name
  "contacts/#{number}/variables/#{name}"
end

#id(number) ⇒ Object



11
12
13
# File 'lib/portatext/command/api/contacts.rb', line 11

def id(number)
  set :number, number
end

#name(name) ⇒ Object



23
24
25
# File 'lib/portatext/command/api/contacts.rb', line 23

def name(name)
  set :name, name
end

#page(page) ⇒ Object



19
20
21
# File 'lib/portatext/command/api/contacts.rb', line 19

def page(page)
  set :page, page
end

#save_to(file) ⇒ Object



36
37
38
# File 'lib/portatext/command/api/contacts.rb', line 36

def save_to(file)
  set :accept_file, file
end

#set_all(variables) ⇒ Object

rubocop:disable Style/AccessorMethodName



41
42
43
44
45
46
# File 'lib/portatext/command/api/contacts.rb', line 41

def set_all(variables)
  variables = variables.reduce([]) do |acc, v|
    acc << { key: v[0], value: v[1] }
  end
  set :variables, variables
end

#set_to(name, value) ⇒ Object



27
28
29
30
# File 'lib/portatext/command/api/contacts.rb', line 27

def set_to(name, value)
  self.name name
  set :value, value
end

#with_contact_listsObject



15
16
17
# File 'lib/portatext/command/api/contacts.rb', line 15

def with_contact_lists
  set :with_contact_lists, true
end