custplace 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +6 -0
- data/Gemfile.lock +25 -0
- data/lib/custplace/answers.rb +13 -0
- data/lib/custplace/base.rb +49 -0
- data/lib/custplace/client.rb +34 -0
- data/lib/custplace/entities/answer.rb +19 -0
- data/lib/custplace/entities/author.rb +16 -0
- data/lib/custplace/entities/review.rb +26 -0
- data/lib/custplace/entities/store.rb +16 -0
- data/lib/custplace/meta_methods.rb +58 -0
- data/lib/custplace/reviews.rb +40 -0
- data/lib/custplace/stores.rb +40 -0
- data/lib/custplace/version.rb +5 -0
- data/lib/custplace.rb +2 -0
- metadata +15 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f968fdfbb429a78b57e20e0d111af237df2dd3aaa6d91205ef1ee469be6683db
|
4
|
+
data.tar.gz: 0d2881308c38fe25297c83f015d086699c731efe9bae01c6d1ffe1b4ba1fddef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c61fa5ebda18f8495047d5bcca4ba184a67a6cfa8bbf9e442190df3e5780bde601834ae2bb15b23e3e5b27cc52c45fe1681e35122d4fd27025c27a7bf9ac2e9e
|
7
|
+
data.tar.gz: 1ebb030469ba3be87250170c22b5aac92dc89dadf537b2ce50a6eaba7ec0b5ddce0c5f91f90d0113d3961cd6c5d2b911c69754decea3bc3733d4c3f4153c8578
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
custplace (0.0.6)
|
5
|
+
httparty (< 1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
httparty (0.21.0)
|
11
|
+
mini_mime (>= 1.0.0)
|
12
|
+
multi_xml (>= 0.5.2)
|
13
|
+
mini_mime (1.1.5)
|
14
|
+
multi_xml (0.6.0)
|
15
|
+
|
16
|
+
PLATFORMS
|
17
|
+
arm64-darwin-21
|
18
|
+
ruby
|
19
|
+
|
20
|
+
DEPENDENCIES
|
21
|
+
custplace!
|
22
|
+
httparty
|
23
|
+
|
24
|
+
BUNDLED WITH
|
25
|
+
2.5.5
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'custplace/base'
|
2
|
+
require 'custplace/entities/review'
|
3
|
+
|
4
|
+
module Custplace
|
5
|
+
class Reviews < Custplace::Base
|
6
|
+
|
7
|
+
def reply(review_id, message)
|
8
|
+
response = post("/answers", params: { message: message, message_id: review_id })
|
9
|
+
Custplace::Entities::Answer.new(response["data"])
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
module Custplace
|
3
|
+
class Base
|
4
|
+
include HTTParty
|
5
|
+
|
6
|
+
base_uri 'https://apis.custplace.com/v3'
|
7
|
+
|
8
|
+
API_VERSION = '3.1.0'
|
9
|
+
|
10
|
+
attr_accessor :client
|
11
|
+
|
12
|
+
# Initialize a new Custplace::Api::Base
|
13
|
+
#
|
14
|
+
# @param client [Custplace::Client] the client to use for the api
|
15
|
+
# @return [Custplace::Api::Base]
|
16
|
+
def initialize(client)
|
17
|
+
@client = client
|
18
|
+
end
|
19
|
+
|
20
|
+
def default_headers
|
21
|
+
{
|
22
|
+
"Custplace-Version": API_VERSION,
|
23
|
+
"Authorization": "Bearer #{client.access_token}"
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def get(path, params: {})
|
28
|
+
response = self.class.get("#{account_base_url}#{path}", query: params, headers: default_headers)
|
29
|
+
parsed_response = response.parsed_response
|
30
|
+
parsed_response
|
31
|
+
end
|
32
|
+
|
33
|
+
def post(path, params: {})
|
34
|
+
response = self.class.post("#{account_base_url}#{path}", body: params.to_json, headers: default_headers)
|
35
|
+
parsed_response = response.parsed_response
|
36
|
+
parsed_response
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# Get the base url for the account
|
42
|
+
#
|
43
|
+
# @return [String] the base url for the account
|
44
|
+
def account_base_url
|
45
|
+
"/#{client.account_id}"
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'custplace/stores'
|
2
|
+
require 'custplace/reviews'
|
3
|
+
require 'custplace/answers'
|
4
|
+
|
5
|
+
module Custplace
|
6
|
+
class Client
|
7
|
+
|
8
|
+
attr_reader :account_id, :access_token
|
9
|
+
|
10
|
+
# Public: Initialize a new Custplace::Client
|
11
|
+
#
|
12
|
+
# @param account_id [String] the account id found in custplace account url
|
13
|
+
# @param access_token [String] the access token for the account found in the integration page on Custplace
|
14
|
+
# @param options [Hash] the options to initialize the client with
|
15
|
+
# @return [Custplace::Client]
|
16
|
+
def initialize(account_id, access_token, options = {})
|
17
|
+
@account_id = account_id.to_s
|
18
|
+
@access_token = access_token
|
19
|
+
end
|
20
|
+
|
21
|
+
def stores
|
22
|
+
@stores ||= Custplace::Stores.new(self)
|
23
|
+
end
|
24
|
+
|
25
|
+
def reviews
|
26
|
+
@reviews ||= Custplace::Reviews.new(self)
|
27
|
+
end
|
28
|
+
|
29
|
+
def answers
|
30
|
+
@answers ||= Custplace::Answers.new(self)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'custplace/meta_methods'
|
2
|
+
# Describe the store entity to return in the store api
|
3
|
+
module Custplace
|
4
|
+
module Entities
|
5
|
+
class Answer < Custplace::MetaMethods
|
6
|
+
|
7
|
+
object_attr_reader :id
|
8
|
+
object_attr_reader :message
|
9
|
+
object_attr_reader :is_official
|
10
|
+
object_attr_reader :is_private
|
11
|
+
object_attr_reader :source
|
12
|
+
object_attr_reader :author, Custplace::Entities::Author
|
13
|
+
|
14
|
+
object_attr_reader :created_at, Time
|
15
|
+
object_attr_reader :updated_at, Time
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'custplace/meta_methods'
|
2
|
+
# Describe the store entity to return in the store api
|
3
|
+
module Custplace
|
4
|
+
module Entities
|
5
|
+
class Author < Custplace::MetaMethods
|
6
|
+
|
7
|
+
object_attr_reader :id
|
8
|
+
object_attr_reader :firstname
|
9
|
+
object_attr_reader :lastname
|
10
|
+
object_attr_reader :fullname
|
11
|
+
object_attr_reader :email
|
12
|
+
object_attr_reader :username
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'custplace/meta_methods'
|
2
|
+
require 'custplace/entities/author'
|
3
|
+
require 'custplace/entities/answer'
|
4
|
+
# Describe the store entity to return in the store api
|
5
|
+
module Custplace
|
6
|
+
module Entities
|
7
|
+
class Review < Custplace::MetaMethods
|
8
|
+
|
9
|
+
object_attr_reader :id
|
10
|
+
object_attr_reader :source
|
11
|
+
object_attr_reader :type
|
12
|
+
object_attr_reader :rating_note
|
13
|
+
object_attr_reader :answers_count
|
14
|
+
object_attr_reader :shop, Custplace::Entities::Store, method_alias: :store
|
15
|
+
object_attr_reader :locale
|
16
|
+
object_attr_reader :subject
|
17
|
+
object_attr_reader :message
|
18
|
+
object_attr_reader :author, Custplace::Entities::Author
|
19
|
+
object_attr_reader :answers, [Custplace::Entities::Answer]
|
20
|
+
|
21
|
+
object_attr_reader :created_at, Time
|
22
|
+
object_attr_reader :updated_at, Time
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'custplace/meta_methods'
|
2
|
+
# Describe the store entity to return in the store api
|
3
|
+
module Custplace
|
4
|
+
module Entities
|
5
|
+
class Store < Custplace::MetaMethods
|
6
|
+
|
7
|
+
object_attr_reader :id
|
8
|
+
object_attr_reader :name
|
9
|
+
object_attr_reader :type
|
10
|
+
object_attr_reader :store_code
|
11
|
+
object_attr_reader :reviews_count
|
12
|
+
object_attr_reader :score
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Custplace
|
2
|
+
class MetaMethods
|
3
|
+
include Memoizable
|
4
|
+
|
5
|
+
attr_reader :attrs, :keys
|
6
|
+
|
7
|
+
def initialize(data)
|
8
|
+
@attrs = data.is_a?(Hash) ? data.with_indifferent_access : data
|
9
|
+
end
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def object_attr_reader(key1, klass=nil, **args)
|
13
|
+
if key1.is_a?(Array)
|
14
|
+
key1.each do |key|
|
15
|
+
define_attribute_method(key, klass, args)
|
16
|
+
end
|
17
|
+
else
|
18
|
+
define_attribute_method(key1, klass, args)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Dynamically define a method for an attribute
|
23
|
+
#
|
24
|
+
# @param key1 [Symbol], or [Array]
|
25
|
+
# @param klass [Symbol]
|
26
|
+
# @param method_alias [Symbol] - alias
|
27
|
+
# @param target_alias [Symbol] - key for this item in the target class
|
28
|
+
# @param include_keys [Symbol] - used in define_attribute_method not here
|
29
|
+
# @param extra_key [Symbol] - down an extra level. IE progression: { raids: [...] }
|
30
|
+
def define_attribute_method(key1, klass = nil, method_alias: key1, target_alias: nil, include_keys: nil, extra_key: nil)
|
31
|
+
define_method(method_alias) do ||
|
32
|
+
target = extra_key.nil? ? @attrs[key1] : @attrs[key1].nil? ? nil : @attrs[key1][extra_key]
|
33
|
+
if target.nil?
|
34
|
+
nil
|
35
|
+
else
|
36
|
+
if klass.nil?
|
37
|
+
target
|
38
|
+
else
|
39
|
+
if klass.is_a?(Array)
|
40
|
+
target.map do |t|
|
41
|
+
klass.first.new(t)
|
42
|
+
end
|
43
|
+
else
|
44
|
+
klass.new(target)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
begin
|
50
|
+
return memoize(method_alias)
|
51
|
+
rescue Exception => e
|
52
|
+
Appsignal.send_error(e)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'custplace/base'
|
2
|
+
require 'custplace/entities/review'
|
3
|
+
|
4
|
+
module Custplace
|
5
|
+
class Reviews < Custplace::Base
|
6
|
+
|
7
|
+
# Get the list of all reviews
|
8
|
+
#
|
9
|
+
# @param params [Hash] the params to use for the request
|
10
|
+
# @return [Array<Custplace::Entities::Store>] the list of stores
|
11
|
+
def list(params: {})
|
12
|
+
page = 1
|
13
|
+
reviews = []
|
14
|
+
response = get("/messages", params: params.merge(page: page, per_page: 100 ))
|
15
|
+
data = response["data"]
|
16
|
+
reviews = reviews.concat(data.map { |review| Custplace::Entities::Review.new(review) })
|
17
|
+
pagination = response["links"]
|
18
|
+
|
19
|
+
while pagination["next"]
|
20
|
+
page += 1
|
21
|
+
response = get("/messages", params: params.merge(page: page))
|
22
|
+
data = response["data"]
|
23
|
+
reviews = reviews.concat(data.map { |review| Custplace::Entities::Review.new(review) })
|
24
|
+
pagination = response["links"]
|
25
|
+
end
|
26
|
+
|
27
|
+
reviews
|
28
|
+
end
|
29
|
+
|
30
|
+
# Retrieves the details of an existing review.
|
31
|
+
#
|
32
|
+
# @param review_id [String] the id of the review to retrieve
|
33
|
+
# @return [Custplace::Entities::Store] the store
|
34
|
+
def find(review_id)
|
35
|
+
response = get("/messages/#{review_id}")
|
36
|
+
Custplace::Entities::Review.new(response["data"])
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'custplace/base'
|
2
|
+
require 'custplace/entities/store'
|
3
|
+
|
4
|
+
module Custplace
|
5
|
+
class Stores < Custplace::Base
|
6
|
+
|
7
|
+
# Get the list of all active stores
|
8
|
+
#
|
9
|
+
# @param params [Hash] the params to use for the request
|
10
|
+
# @return [Array<Custplace::Entities::Store>] the list of stores
|
11
|
+
def list(params: {})
|
12
|
+
page = 1
|
13
|
+
stores = []
|
14
|
+
response = get("/shops", params: params.merge(page: page))
|
15
|
+
data = response["data"]
|
16
|
+
stores = stores.concat(data.map { |store| Custplace::Entities::Store.new(store) })
|
17
|
+
pagination = response["links"]
|
18
|
+
|
19
|
+
while pagination["next"]
|
20
|
+
page += 1
|
21
|
+
response = get("/shops", params: params.merge(page: page))
|
22
|
+
data = response["data"]
|
23
|
+
stores = stores.concat(data.map { |store| Custplace::Entities::Store.new(store) })
|
24
|
+
pagination = response["links"]
|
25
|
+
end
|
26
|
+
|
27
|
+
stores
|
28
|
+
end
|
29
|
+
|
30
|
+
# Retrieves the details of an existing store.
|
31
|
+
#
|
32
|
+
# @param store_id [String] the id of the store to retrieve
|
33
|
+
# @return [Custplace::Entities::Store] the store
|
34
|
+
def find(store_id)
|
35
|
+
response = get("/shops/#{store_id}")
|
36
|
+
Custplace::Entities::Store.new(response["data"])
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
data/lib/custplace.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: custplace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Qualimétrie
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
11
|
date: 2024-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
@@ -30,7 +30,20 @@ executables: []
|
|
30
30
|
extensions: []
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
|
+
- Gemfile
|
34
|
+
- Gemfile.lock
|
33
35
|
- lib/custplace.rb
|
36
|
+
- lib/custplace/answers.rb
|
37
|
+
- lib/custplace/base.rb
|
38
|
+
- lib/custplace/client.rb
|
39
|
+
- lib/custplace/entities/answer.rb
|
40
|
+
- lib/custplace/entities/author.rb
|
41
|
+
- lib/custplace/entities/review.rb
|
42
|
+
- lib/custplace/entities/store.rb
|
43
|
+
- lib/custplace/meta_methods.rb
|
44
|
+
- lib/custplace/reviews.rb
|
45
|
+
- lib/custplace/stores.rb
|
46
|
+
- lib/custplace/version.rb
|
34
47
|
homepage: https://rubygems.org/gems/custplace
|
35
48
|
licenses:
|
36
49
|
- MIT
|