Sha256: dc93d08e9b2415f5efd56b795400973123edf472e02f1a722ab973b23275baff

Contents?: true

Size: 1.82 KB

Versions: 30

Compression:

Stored size: 1.82 KB

Contents

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

        def name(name)
          set :name, name
        end

        def description(description)
          set :description, description
        end

        def csv(file)
          set :file, file
        end

        def save_to(file)
          set :accept_file, file
        end

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

        def page(page)
          set :page, page
        end

        # rubocop:disable Metrics/MethodLength
        # rubocop:disable Metrics/AbcSize
        def endpoint(_method)
          return 'contact_lists' if @args[:id].nil?
          id = @args[:id]
          @args.delete :id
          number = @args[:number]
          @args.delete :number
          page = @args[:page]
          @args.delete :page
          return "contact_lists/#{id}/contacts/#{number}" unless number.nil?
          return "contact_lists/#{id}/contacts" unless @args[:file].nil?
          return "contact_lists/#{id}/contacts" unless @args[:accept_file].nil?
          return "contact_lists/#{id}/contacts?page=#{page}" unless page.nil?
          "contact_lists/#{id}"
        end
        # rubocop:enable Metrics/AbcSize
        # rubocop:enable Metrics/MethodLength
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

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