Sha256: 4c98428e20fbe02a62de67b1f6d5b6a39e1086102701b99b616dae142ccb5760

Contents?: true

Size: 1.97 KB

Versions: 34

Compression:

Stored size: 1.97 KB

Contents

module PortaText
  module Command
    module Api
      # The contacts endpoint.
      # https://github.com/PortaText/docs/wiki/REST-API#api_all_contacts
      #
      # Author::    Marcelo Gornstein (mailto:marcelog@portatext.com)
      # Copyright:: Copyright (c) 2015 PortaText
      # License::   Apache-2.0
      class Contacts < Base
        def id(number)
          set :number, number
        end

        def with_contact_lists
          set :with_contact_lists, true
        end

        def page(page)
          set :page, page
        end

        def name(name)
          set :name, name
        end

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

        def csv(file)
          set :file, file
        end

        def save_to(file)
          set :accept_file, file
        end

        # rubocop:disable Style/AccessorMethodName
        def set_all(variables)
          variables = variables.reduce([]) do |acc, v|
            acc << { key: v[0], value: v[1] }
          end
          set :variables, variables
        end
        # rubocop:enable Style/AccessorMethodName

        # rubocop:disable Metrics/MethodLength
        # rubocop:disable Metrics/AbcSize
        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
        # rubocop:enable Metrics/MethodLength
        # rubocop:enable Metrics/AbcSize
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
portatext-1.6.1 lib/portatext/command/api/contacts.rb
portatext-1.6.0 lib/portatext/command/api/contacts.rb
portatext-1.5.23 lib/portatext/command/api/contacts.rb
portatext-1.5.22 lib/portatext/command/api/contacts.rb
portatext-1.5.21 lib/portatext/command/api/contacts.rb
portatext-1.5.20 lib/portatext/command/api/contacts.rb
portatext-1.5.19 lib/portatext/command/api/contacts.rb
portatext-1.5.18 lib/portatext/command/api/contacts.rb
portatext-1.5.17 lib/portatext/command/api/contacts.rb
portatext-1.5.16 lib/portatext/command/api/contacts.rb
portatext-1.5.15 lib/portatext/command/api/contacts.rb
portatext-1.5.14 lib/portatext/command/api/contacts.rb
portatext-1.5.13 lib/portatext/command/api/contacts.rb
portatext-1.5.12 lib/portatext/command/api/contacts.rb
portatext-1.5.11 lib/portatext/command/api/contacts.rb
portatext-1.5.10 lib/portatext/command/api/contacts.rb
portatext-1.5.9 lib/portatext/command/api/contacts.rb
portatext-1.5.8 lib/portatext/command/api/contacts.rb
portatext-1.5.7 lib/portatext/command/api/contacts.rb
portatext-1.5.6 lib/portatext/command/api/contacts.rb