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.5.5 lib/portatext/command/api/contacts.rb
portatext-1.5.4 lib/portatext/command/api/contacts.rb
portatext-1.5.3 lib/portatext/command/api/contacts.rb
portatext-1.5.2 lib/portatext/command/api/contacts.rb
portatext-1.5.1 lib/portatext/command/api/contacts.rb
portatext-1.5.0 lib/portatext/command/api/contacts.rb
portatext-1.4.4 lib/portatext/command/api/contacts.rb
portatext-1.4.3 lib/portatext/command/api/contacts.rb
portatext-1.4.2 lib/portatext/command/api/contacts.rb
portatext-1.4.1 lib/portatext/command/api/contacts.rb
portatext-1.4.0 lib/portatext/command/api/contacts.rb
portatext-1.3.1 lib/portatext/command/api/contacts.rb
portatext-1.3.0 lib/portatext/command/api/contacts.rb
portatext-1.2.0 lib/portatext/command/api/contacts.rb