class Myfinance::Resources::ClassificationCenter

A wrapper to Myfinance classification center API

API

Documentation: app.myfinance.com.br/docs/api/classification_centers

Public Instance Methods

create(params) click to toggle source

Creates a classification center

API

Method: POST /classification_centers

Documentation: app.myfinance.com.br/docs/api/classification_centers#post_create

# File lib/myfinance/resources/classification_center.rb, line 47
def create(params)
  http.post(
    "/classification_centers", body: { classification_center: params }
  ) do |response|
    respond_with_object response, "classification_center"
  end
end
destroy(id) click to toggle source

Destroy a classification center

API

Method: DELETE /classification_centers/:id

Documentation: app.myfinance.com.br/docs/api/classification_centers#delete_destroy

# File lib/myfinance/resources/classification_center.rb, line 80
def destroy(id)
  http.delete("/classification_centers/#{id}", body: {}) do |response|
    respond_with_object response, "classification_center"
  end
end
find(id) click to toggle source

Show a classification center

API

Method: GET /classification_centers/:id

Documentation: app.myfinance.com.br/docs/api/classification_centers#get_show

# File lib/myfinance/resources/classification_center.rb, line 34
def find(id)
  http.get("/classification_centers/#{id}", body: {}) do |response|
    respond_with_object response, "classification_center"
  end
end
find_all(params = {}) click to toggle source

List all classification centers, supplying optional params for refinement

API

Method: GET /classification_centers

Documentation: app.myfinance.com.br/docs/api/classification_centers#get_index

# File lib/myfinance/resources/classification_center.rb, line 18
def find_all(params = {})
  search_endpoint = build_search_endpoint(params)

  http.get(search_endpoint) do |response|
    respond_with_collection(response)
  end
end
update(id, params) click to toggle source

Updates a classification center

API

Method: PUT /classification_centers/:id

Documentation: app.myfinance.com.br/docs/api/classification_centers#put_update

# File lib/myfinance/resources/classification_center.rb, line 63
def update(id, params)
  http.put(
    "/classification_centers/#{id}",
    body: { classification_center: params }
  ) do |response|
    respond_with_object response, "classification_center"
  end
end

Private Instance Methods

build_search_endpoint(params) click to toggle source
# File lib/myfinance/resources/classification_center.rb, line 92
def build_search_endpoint(params)
  query_string = query(params).join("&")
  URI.encode("#{endpoint}?#{query_string}")
end
endpoint() click to toggle source
# File lib/myfinance/resources/classification_center.rb, line 88
def endpoint
  "/classification_centers"
end
query(params) click to toggle source
# File lib/myfinance/resources/classification_center.rb, line 97
def query(params)
  page = params.delete(:page)
  per_page = params.delete(:per_page)
  query = params.map { |key, value| "search[#{key}]=#{value}" }
  query << "page=#{page}" if page
  query << "per_page=#{per_page}" if per_page
  query
end