class PortaText::Command::Api::Contacts

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

Author

Marcelo Gornstein (marcelog@portatext.com)

Copyright

Copyright © 2015 PortaText

License

Apache-2.0

Public Instance Methods

csv(file) click to toggle source
# File lib/portatext/command/api/contacts.rb, line 32
def csv(file)
  set :file, file
end
endpoint(_method) click to toggle source

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

# 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) click to toggle source
# File lib/portatext/command/api/contacts.rb, line 11
def id(number)
  set :number, number
end
name(name) click to toggle source
# File lib/portatext/command/api/contacts.rb, line 23
def name(name)
  set :name, name
end
page(page) click to toggle source
# File lib/portatext/command/api/contacts.rb, line 19
def page(page)
  set :page, page
end
save_to(file) click to toggle source
# File lib/portatext/command/api/contacts.rb, line 36
def save_to(file)
  set :accept_file, file
end
set_all(variables) click to toggle source

rubocop:disable Style/AccessorMethodName

# 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) click to toggle source
# File lib/portatext/command/api/contacts.rb, line 27
def set_to(name, value)
  self.name name
  set :value, value
end
with_contact_lists() click to toggle source
# File lib/portatext/command/api/contacts.rb, line 15
def with_contact_lists
  set :with_contact_lists, true
end