Class: Emites::Resources::Service

Inherits:
Base
  • Object
show all
Defined in:
lib/emites/resources/service.rb

Overview

A wrapper to Emites services API

API

Documentation: myfreecomm.github.io/emites/sandbox/v1/modules/service_values.html

Examples:

Listing all services:

client = Emites.client("MY_SECRET_TOKEN")
client.services.list

Creating a service:

client = Emites.client("MY_SECRET_TOKEN")
client.services.create({emitter_id: 1, name: "Serviço"})

See Also:

Instance Attribute Summary

Attributes inherited from Base

#http

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from Hooks

#notify

Constructor Details

This class inherits a constructor from Emites::Resources::Base

Instance Method Details

#calculate_liquid_amount(id, params) ⇒ Emites::Entities::Service

Calculates the liquid amount based on service

API

Method: POST /api/v1/service-values/:id/calculation-liquid-amount

Documentation: myfreecomm.github.io/emites/sandbox/v1/modules/service_values.html#calculo-de-valor-liquido-da-nfse

Parameters:

  • id (Integer)

    the Service id

  • params (Hash)

    a hash with Service service_amount

Returns:



105
106
107
108
109
# File 'lib/emites/resources/service.rb', line 105

def calculate_liquid_amount(id, params)
  http.post("/service-values/#{id}/calculation-liquid-amount", { body: params }) do |response|
    respond_with_entity(response)
  end
end

#create(params) ⇒ Emites::Entities::Service

Creates a Service related to the Account

API

Method: POST /api/v1/service-values

Documentation: myfreecomm.github.io/emites/sandbox/v1/modules/service_values.html#criacao

Parameters:

  • params (Hash)

    a hash with Service attributes

Returns:



29
30
31
32
33
# File 'lib/emites/resources/service.rb', line 29

def create(params)
  http.post("/service-values", { body: params }) do |response|
    respond_with_entity(response)
  end
end

#destroy(id) ⇒ Boolean

Deletes a Service by it’s id. Returns true</true> if deletion performed well, otherwise, returns <tt>false.

API

Method: DELETE /api/v1/service-values/:id

Documentation: myfreecomm.github.io/emites/sandbox/v1/modules/service_values.html#remocao

Parameters:

  • id (Integer)

    the Service id

Returns:

  • (Boolean)

    whether deletion was performed or not



89
90
91
92
93
# File 'lib/emites/resources/service.rb', line 89

def destroy(id)
  http.delete("/service-values/#{id}") do |response|
    response.code == 204
  end
end

#info(id) ⇒ Emites::Entities::Service

Retrieves a Service by it’s id

API

Method: GET /api/v1/service-values/:id

Documentation: myfreecomm.github.io/emites/sandbox/v1/modules/service_values.html#detalhes

Parameters:

  • id (Integer)

    the Service id

Returns:



44
45
46
47
48
# File 'lib/emites/resources/service.rb', line 44

def info(id)
  http.get("/service-values/#{id}") do |response|
    respond_with_entity(response)
  end
end

#listArray

Lists all services related to the account

API

Method: GET /api/v1/service-values

Documentation: myfreecomm.github.io/emites/sandbox/v1/modules/service_values.html#listagem

Returns:

  • (Array)

    an array of Service



58
59
60
61
62
# File 'lib/emites/resources/service.rb', line 58

def list
  http.get("/service-values") do |response|
    respond_with_collection(response)
  end
end

#search(params) ⇒ Array

Lists all services related to the account matching search results

API

Method: GET /api/v1/service-values?name=:name

Documentation: myfreecomm.github.io/emites/sandbox/v1/modules/service_values.html#filtros

Parameters:

  • params (Hash)

    a hash with Service attributes

Returns:

  • (Array)

    an array of Service



73
74
75
76
77
# File 'lib/emites/resources/service.rb', line 73

def search(params)
  http.get("/service-values", { params: params }) do |response|
    respond_with_collection(response)
  end
end