Class: Custplace::Reviews

Inherits:
Base
  • Object
show all
Defined in:
lib/custplace/answers.rb,
lib/custplace/reviews.rb

Constant Summary

Constants inherited from Base

Base::API_VERSION

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#default_headers, #get, #initialize, #post

Constructor Details

This class inherits a constructor from Custplace::Base

Instance Method Details

#find(review_id) ⇒ Custplace::Entities::Store

Retrieves the details of an existing review.

Parameters:

  • review_id (String)

    the id of the review to retrieve

Returns:



34
35
36
37
# File 'lib/custplace/reviews.rb', line 34

def find(review_id)
  response = get("/messages/#{review_id}")
  Custplace::Entities::Review.new(response["data"])
end

#list(params: {}) ⇒ Array<Custplace::Entities::Store>

Get the list of all reviews

Parameters:

  • params (Hash) (defaults to: {})

    the params to use for the request

Returns:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/custplace/reviews.rb', line 11

def list(params: {})
  page = 1
  reviews = []
  response = get("/messages", params: params.merge(page: page, per_page: 100 ))
  data = response["data"]
  reviews = reviews.concat(data.map { |review| Custplace::Entities::Review.new(review) })
  pagination = response["links"]

  while pagination["next"]
    page += 1
    response = get("/messages", params: params.merge(page: page))
    data = response["data"]
    reviews = reviews.concat(data.map { |review| Custplace::Entities::Review.new(review) })
    pagination = response["links"]
  end

  reviews
end

#reply(review_id, message) ⇒ Object



7
8
9
10
# File 'lib/custplace/answers.rb', line 7

def reply(review_id, message)
  response = post("/answers", params: { message: message, message_id: review_id })
  Custplace::Entities::Answer.new(response["data"])
end