user_engage 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +12 -5
- data/.travis.yml +2 -2
- data/Gemfile +2 -0
- data/Gemfile.lock +17 -9
- data/Rakefile +2 -0
- data/TODO.md +12 -29
- data/bin/console +1 -0
- data/lib/user_engage/attribute.rb +2 -0
- data/lib/user_engage/base_model.rb +6 -0
- data/lib/user_engage/client.rb +29 -3
- data/lib/user_engage/company.rb +62 -0
- data/lib/user_engage/configuration.rb +2 -0
- data/lib/user_engage/errors.rb +6 -1
- data/lib/user_engage/list.rb +2 -0
- data/lib/user_engage/operation/all.rb +24 -0
- data/lib/user_engage/operation/create.rb +68 -0
- data/lib/user_engage/operation/destroy.rb +3 -0
- data/lib/user_engage/operation/find.rb +29 -8
- data/lib/user_engage/operation/update_attributes.rb +56 -0
- data/lib/user_engage/resource_collection.rb +110 -0
- data/lib/user_engage/tag.rb +2 -0
- data/lib/user_engage/user.rb +19 -5
- data/lib/user_engage/version.rb +3 -1
- data/lib/user_engage.rb +3 -0
- data/user_engage.gemspec +4 -2
- metadata +24 -6
- data/NetrwTreeListing 3 +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5b7910a1cb3d819d0cbd2cb74977cfb9f23cead126b0051989e51862f434f733
|
|
4
|
+
data.tar.gz: 54c6ee7b2c04cb3bd9236ee1abd7f980a5fb80191d0268ed2382100541474925
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c06e6bb089219e9e9fd7a1a6e735a41cbb81850f0a05068967b6b93ddaf97e5dee46a0b46a187e18b0ba37f5ebca1a71571f33e5716b54a3812e1284cfbb392a
|
|
7
|
+
data.tar.gz: 84c2752edf54a3bc3644f497f7ed1c6e9282c4c15c6cbd711eef7e4101a90fef54b3e7fa7819d22c4a89aec634a8610a93f4a8a8bb2c4c31b69b92d7cc7bfd48
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 2.5.1
|
|
3
|
+
|
|
4
|
+
Metrics/BlockLength:
|
|
5
|
+
Exclude:
|
|
6
|
+
- 'spec/**/*'
|
|
7
|
+
- 'user_engage.gemspec'
|
|
8
|
+
|
|
9
|
+
Style/CommentedKeyword:
|
|
10
|
+
Enabled: false
|
|
11
|
+
|
|
1
12
|
Style/Documentation:
|
|
2
13
|
Enabled: false
|
|
3
14
|
|
|
4
|
-
Style/
|
|
15
|
+
Style/MultilineTernaryOperator:
|
|
5
16
|
Enabled: false
|
|
6
17
|
|
|
7
18
|
Style/NumericLiterals:
|
|
8
19
|
Enabled: false
|
|
9
|
-
|
|
10
|
-
Metrics/BlockLength:
|
|
11
|
-
Exclude:
|
|
12
|
-
- 'spec/**/*'
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
user_engage (0.0.
|
|
4
|
+
user_engage (0.0.7)
|
|
5
5
|
dry-struct (~> 0.5)
|
|
6
6
|
faraday (>= 0.12)
|
|
7
7
|
|
|
@@ -11,6 +11,7 @@ GEM
|
|
|
11
11
|
addressable (2.5.2)
|
|
12
12
|
public_suffix (>= 2.0.2, < 4.0)
|
|
13
13
|
ast (2.4.0)
|
|
14
|
+
coderay (1.1.2)
|
|
14
15
|
concurrent-ruby (1.0.5)
|
|
15
16
|
crack (0.4.3)
|
|
16
17
|
safe_yaml (~> 1.0.0)
|
|
@@ -45,11 +46,16 @@ GEM
|
|
|
45
46
|
multipart-post (>= 1.2, < 3)
|
|
46
47
|
hashdiff (0.3.7)
|
|
47
48
|
ice_nine (0.11.2)
|
|
49
|
+
jaro_winkler (1.5.1)
|
|
50
|
+
method_source (0.9.0)
|
|
48
51
|
multipart-post (2.0.0)
|
|
49
52
|
parallel (1.12.1)
|
|
50
|
-
parser (2.
|
|
51
|
-
ast (~> 2.
|
|
52
|
-
powerpack (0.1.
|
|
53
|
+
parser (2.5.1.2)
|
|
54
|
+
ast (~> 2.4.0)
|
|
55
|
+
powerpack (0.1.2)
|
|
56
|
+
pry (0.11.3)
|
|
57
|
+
coderay (~> 1.1.0)
|
|
58
|
+
method_source (~> 0.9.0)
|
|
53
59
|
public_suffix (3.0.1)
|
|
54
60
|
rainbow (3.0.0)
|
|
55
61
|
rake (10.5.0)
|
|
@@ -66,16 +72,17 @@ GEM
|
|
|
66
72
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
67
73
|
rspec-support (~> 3.7.0)
|
|
68
74
|
rspec-support (3.7.1)
|
|
69
|
-
rubocop (0.
|
|
75
|
+
rubocop (0.59.2)
|
|
76
|
+
jaro_winkler (~> 1.5.1)
|
|
70
77
|
parallel (~> 1.10)
|
|
71
|
-
parser (>= 2.
|
|
78
|
+
parser (>= 2.5, != 2.5.1.1)
|
|
72
79
|
powerpack (~> 0.1)
|
|
73
80
|
rainbow (>= 2.2.2, < 4.0)
|
|
74
81
|
ruby-progressbar (~> 1.7)
|
|
75
82
|
unicode-display_width (~> 1.0, >= 1.0.1)
|
|
76
|
-
ruby-progressbar (1.
|
|
83
|
+
ruby-progressbar (1.10.0)
|
|
77
84
|
safe_yaml (1.0.4)
|
|
78
|
-
unicode-display_width (1.
|
|
85
|
+
unicode-display_width (1.4.0)
|
|
79
86
|
vcr (4.0.0)
|
|
80
87
|
webmock (3.3.0)
|
|
81
88
|
addressable (>= 2.3.6)
|
|
@@ -88,9 +95,10 @@ PLATFORMS
|
|
|
88
95
|
DEPENDENCIES
|
|
89
96
|
bundler (~> 1.16)
|
|
90
97
|
dotenv (~> 2.2)
|
|
98
|
+
pry (~> 0.11.3)
|
|
91
99
|
rake (~> 10.0)
|
|
92
100
|
rspec (~> 3.0)
|
|
93
|
-
rubocop (~> 0.
|
|
101
|
+
rubocop (~> 0.59)
|
|
94
102
|
user_engage!
|
|
95
103
|
vcr (~> 4.0)
|
|
96
104
|
webmock (~> 3.3)
|
data/Rakefile
CHANGED
data/TODO.md
CHANGED
|
@@ -1,52 +1,36 @@
|
|
|
1
1
|
# Open ToDos:
|
|
2
2
|
## Users
|
|
3
|
-
* [
|
|
3
|
+
* [x] Create user
|
|
4
4
|
* [ ] Update user
|
|
5
5
|
* [x] Find user by email
|
|
6
|
+
* [x] Find user by ID
|
|
6
7
|
* [x] Find user by key
|
|
7
8
|
* [x] Find user by phone number
|
|
8
9
|
* [x] Find user by date
|
|
9
10
|
* [x] Delete user
|
|
10
11
|
* [ ] Filter users by custom attribute
|
|
11
|
-
* [
|
|
12
|
-
* [
|
|
12
|
+
* [x] Get single user details
|
|
13
|
+
* [x] Get all users details
|
|
13
14
|
* [ ] Get user segments
|
|
14
15
|
* [ ] Add tag
|
|
15
16
|
* [ ] Remove tag
|
|
16
17
|
* [ ] Add list
|
|
17
18
|
* [ ] Remove list
|
|
18
|
-
* [
|
|
19
|
-
* [
|
|
20
|
-
* [ ] Remove attribute
|
|
21
|
-
* [ ] Get user ping hits
|
|
22
|
-
* [ ] Get user timeline
|
|
23
|
-
* [ ] Get user events
|
|
24
|
-
* [ ] Get user emails
|
|
25
|
-
## Users - custom ID requests
|
|
26
|
-
* [ ] Update user
|
|
27
|
-
* [ ] Find user by ID
|
|
28
|
-
* [ ] Delete user
|
|
29
|
-
* [ ] Get single user details
|
|
30
|
-
* [ ] Get user segments
|
|
31
|
-
* [ ] Add tag
|
|
32
|
-
* [ ] Remove tag
|
|
33
|
-
* [ ] Add list
|
|
34
|
-
* [ ] Remove list
|
|
35
|
-
* [ ] Set attribute
|
|
36
|
-
* [ ] Set multiple attributes
|
|
19
|
+
* [x] Set attribute
|
|
20
|
+
* [x] Set multiple attributes
|
|
37
21
|
* [ ] Remove attribute
|
|
38
22
|
* [ ] Get user ping hits
|
|
39
23
|
* [ ] Get user timeline
|
|
40
24
|
* [ ] Get user events
|
|
41
25
|
* [ ] Get user emails
|
|
42
26
|
## CRM
|
|
43
|
-
* [
|
|
27
|
+
* [x] Create company
|
|
44
28
|
* [ ] Update company
|
|
45
|
-
* [
|
|
46
|
-
* [
|
|
47
|
-
* [
|
|
48
|
-
* [
|
|
49
|
-
* [
|
|
29
|
+
* [x] Delete company
|
|
30
|
+
* [x] Get company
|
|
31
|
+
* [x] Get all companies
|
|
32
|
+
* [x] Set attribute
|
|
33
|
+
* [x] Set multiple attributes
|
|
50
34
|
* [ ] Update company using company ID
|
|
51
35
|
* [ ] Delete company using company ID
|
|
52
36
|
* [ ] Get company using company ID
|
|
@@ -57,7 +41,6 @@
|
|
|
57
41
|
* [ ] Get deal
|
|
58
42
|
* [ ] Get all deals
|
|
59
43
|
* [ ] Set attribute
|
|
60
|
-
* [ ] Set multiple attributes
|
|
61
44
|
* [ ] Create activity
|
|
62
45
|
* [ ] Update activity
|
|
63
46
|
* [ ] Get activity
|
data/bin/console
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'dry-struct'
|
|
2
4
|
|
|
3
5
|
module UserEngage
|
|
@@ -9,5 +11,9 @@ module UserEngage
|
|
|
9
11
|
transform_types do |type|
|
|
10
12
|
type.meta(omittable: true)
|
|
11
13
|
end
|
|
14
|
+
|
|
15
|
+
def resource_name
|
|
16
|
+
self.class.resource_name
|
|
17
|
+
end
|
|
12
18
|
end
|
|
13
19
|
end
|
data/lib/user_engage/client.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'faraday'
|
|
2
4
|
|
|
3
5
|
module UserEngage
|
|
@@ -11,7 +13,7 @@ module UserEngage
|
|
|
11
13
|
|
|
12
14
|
# Public: Calls the base_url with the given path and parameters
|
|
13
15
|
#
|
|
14
|
-
def get(path, parameters)
|
|
16
|
+
def get(path, parameters = {})
|
|
15
17
|
request(:get, path, parameters)
|
|
16
18
|
end
|
|
17
19
|
|
|
@@ -21,6 +23,12 @@ module UserEngage
|
|
|
21
23
|
request(:delete, path)
|
|
22
24
|
end
|
|
23
25
|
|
|
26
|
+
# Public: Calls the base_url with the given path and parameters
|
|
27
|
+
#
|
|
28
|
+
def post(path, parameters = {})
|
|
29
|
+
request(:post, path, parameters)
|
|
30
|
+
end
|
|
31
|
+
|
|
24
32
|
#####################
|
|
25
33
|
## Private methods ##
|
|
26
34
|
#####################
|
|
@@ -31,7 +39,16 @@ module UserEngage
|
|
|
31
39
|
end
|
|
32
40
|
|
|
33
41
|
def request(method, action_path, parameters = nil)
|
|
34
|
-
path =
|
|
42
|
+
path = action_path.match?(/^https?/) ?
|
|
43
|
+
action_path :
|
|
44
|
+
"api/public#{action_path}"
|
|
45
|
+
|
|
46
|
+
%i[post put patch].include?(method) ?
|
|
47
|
+
json_body_call(method, path, parameters) :
|
|
48
|
+
path_params_call(method, path, parameters)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def path_params_call(method, path, parameters)
|
|
35
52
|
connection.public_send(method, path, parameters) do |request|
|
|
36
53
|
request.headers['Authorization'] = "Token #{@configuration.token}"
|
|
37
54
|
request.headers['Content-Type'] = 'application/json'
|
|
@@ -39,8 +56,17 @@ module UserEngage
|
|
|
39
56
|
end
|
|
40
57
|
end
|
|
41
58
|
|
|
59
|
+
def json_body_call(method, path, parameters)
|
|
60
|
+
connection.public_send(method, path) do |request|
|
|
61
|
+
request.headers['Authorization'] = "Token #{@configuration.token}"
|
|
62
|
+
request.headers['Content-Type'] = 'application/json'
|
|
63
|
+
request.headers['User-Agent'] = "UserEngage-Ruby/#{UserEngage::VERSION}"
|
|
64
|
+
request.body = parameters.to_json
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
42
68
|
def host
|
|
43
|
-
'https://app.userengage.com/'
|
|
69
|
+
'https://app.userengage.com/'
|
|
44
70
|
end
|
|
45
71
|
end
|
|
46
72
|
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'user_engage/base_model'
|
|
4
|
+
require 'user_engage/operation/all'
|
|
5
|
+
require 'user_engage/operation/create'
|
|
6
|
+
require 'user_engage/operation/find'
|
|
7
|
+
require 'user_engage/operation/destroy'
|
|
8
|
+
require 'user_engage/operation/update_attributes'
|
|
9
|
+
|
|
10
|
+
require 'user_engage/attribute'
|
|
11
|
+
|
|
12
|
+
module UserEngage
|
|
13
|
+
class Company < BaseModel
|
|
14
|
+
##############
|
|
15
|
+
## Includes ##
|
|
16
|
+
##############
|
|
17
|
+
extend Operation::All
|
|
18
|
+
extend Operation::Find
|
|
19
|
+
extend Operation::Create
|
|
20
|
+
include Operation::Destroy
|
|
21
|
+
include Operation::UpdateAttributes
|
|
22
|
+
|
|
23
|
+
################
|
|
24
|
+
## Attributes ##
|
|
25
|
+
################
|
|
26
|
+
attribute :address, Types::String
|
|
27
|
+
attribute :approx_employees, Types::Integer
|
|
28
|
+
attribute :attributes, Types::Array.of(UserEngage::Attribute)
|
|
29
|
+
attribute :city, Types::String
|
|
30
|
+
attribute :company_id, Types::Integer
|
|
31
|
+
attribute :country, Types::String
|
|
32
|
+
attribute :created_at, Types::DateTime
|
|
33
|
+
attribute :description, Types::String
|
|
34
|
+
attribute :email, Types::String
|
|
35
|
+
attribute :extra_data, Types::Array
|
|
36
|
+
attribute :id, Types::Integer
|
|
37
|
+
attribute :member_since, Types::DateTime
|
|
38
|
+
attribute :name, Types::String
|
|
39
|
+
attribute :phone_numbers, Types::Array.of(Types::String)
|
|
40
|
+
attribute :postal_code, Types::String
|
|
41
|
+
attribute :region, Types::String
|
|
42
|
+
attribute :updated_at, Types::DateTime
|
|
43
|
+
|
|
44
|
+
###################
|
|
45
|
+
## Class methods ##
|
|
46
|
+
###################
|
|
47
|
+
def self.resource_name
|
|
48
|
+
'companies'
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
#####################
|
|
52
|
+
## Private methods ##
|
|
53
|
+
#####################
|
|
54
|
+
private_class_method def self.supported_find_params
|
|
55
|
+
[]
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
private_class_method def self.required_params
|
|
59
|
+
%i[name]
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
data/lib/user_engage/errors.rb
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module UserEngage
|
|
4
|
+
class CreateNotSuccessfulException < StandardError; end
|
|
2
5
|
class InvalidFindAttributeException < StandardError; end
|
|
3
|
-
class ResourceNotFoundException < StandardError; end
|
|
4
6
|
class NotExistingResourceException < StandardError; end
|
|
7
|
+
class NoNextPageAvailableException < StandardError; end
|
|
8
|
+
class NoPreviousPageAvailableException < StandardError; end
|
|
9
|
+
class ResourceNotFoundException < StandardError; end
|
|
5
10
|
end
|
data/lib/user_engage/list.rb
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'user_engage/resource_collection'
|
|
4
|
+
|
|
5
|
+
module UserEngage
|
|
6
|
+
module Operation
|
|
7
|
+
module All
|
|
8
|
+
def all
|
|
9
|
+
data = fetch_all.merge!(base_class: self)
|
|
10
|
+
UserEngage::ResourceCollection.new(data).tap(&:transform_results!)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
#####################
|
|
14
|
+
## Private methods ##
|
|
15
|
+
#####################
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def fetch_all
|
|
19
|
+
response = UserEngage.client.get("/#{resource_name}/")
|
|
20
|
+
JSON.parse(response.body, symbolize_names: true)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'user_engage/errors'
|
|
4
|
+
|
|
5
|
+
module UserEngage
|
|
6
|
+
module Operation
|
|
7
|
+
module Create
|
|
8
|
+
# Public: Creates a new resource instance, create a new resource
|
|
9
|
+
# through UE API and returns the insance.
|
|
10
|
+
#
|
|
11
|
+
def create(attributes_hash)
|
|
12
|
+
check_for_required_params!(attributes_hash)
|
|
13
|
+
response = create_remote_resource(attributes_hash)
|
|
14
|
+
check_for_response_code!(response)
|
|
15
|
+
construct_new_resource(response)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
#####################
|
|
19
|
+
## Private methods ##
|
|
20
|
+
#####################
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
# Private: Sends the post request with the UE client
|
|
24
|
+
# and returns the response
|
|
25
|
+
#
|
|
26
|
+
def create_remote_resource(attributes_hash)
|
|
27
|
+
path = "/#{resource_name}/"
|
|
28
|
+
UserEngage.client.post(path, attributes_hash)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Private: Creates a new resource instance with
|
|
32
|
+
# the body of the given response.
|
|
33
|
+
#
|
|
34
|
+
def construct_new_resource(response)
|
|
35
|
+
data = JSON.parse(response.body, symbolize_names: true)
|
|
36
|
+
new(data)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Private: Checks for 201 status.
|
|
40
|
+
# If not 200 a UserEngage::CreateNotSuccessfulException with
|
|
41
|
+
# given message gets returned.
|
|
42
|
+
#
|
|
43
|
+
def check_for_response_code!(response)
|
|
44
|
+
return if response.status == 201
|
|
45
|
+
|
|
46
|
+
raise(
|
|
47
|
+
UserEngage::CreateNotSuccessfulException,
|
|
48
|
+
response.body
|
|
49
|
+
)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Private: Checks for the set required_params
|
|
53
|
+
# and raises an CreateNotSuccessfulException with a message
|
|
54
|
+
# if not all are given.
|
|
55
|
+
#
|
|
56
|
+
def check_for_required_params!(attributes_hash)
|
|
57
|
+
return if (
|
|
58
|
+
missing_attributes = required_params - attributes_hash.keys
|
|
59
|
+
).empty?
|
|
60
|
+
|
|
61
|
+
raise(
|
|
62
|
+
UserEngage::CreateNotSuccessfulException,
|
|
63
|
+
"Missing attributes {#{missing_attributes.inspect}}"
|
|
64
|
+
)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'user_engage/errors'
|
|
2
4
|
|
|
3
5
|
module UserEngage
|
|
@@ -20,6 +22,7 @@ module UserEngage
|
|
|
20
22
|
|
|
21
23
|
def check_for_success!(response)
|
|
22
24
|
return true if response.status == 204
|
|
25
|
+
|
|
23
26
|
raise(
|
|
24
27
|
UserEngage::NotExistingResourceException,
|
|
25
28
|
"No resource with ID: #{id} found!"
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'user_engage/errors'
|
|
2
4
|
|
|
3
5
|
module UserEngage
|
|
@@ -15,14 +17,29 @@ module UserEngage
|
|
|
15
17
|
private
|
|
16
18
|
|
|
17
19
|
def get_resource(params)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
response = if params.is_a?(Integer)
|
|
21
|
+
get_by_id(params)
|
|
22
|
+
else
|
|
23
|
+
get_by_hash(params)
|
|
24
|
+
end
|
|
25
|
+
|
|
20
26
|
check_for_existing_resource!(response, params)
|
|
21
27
|
JSON.parse(response.body, symbolize_names: true)
|
|
22
28
|
end
|
|
23
29
|
|
|
30
|
+
def get_by_hash(params)
|
|
31
|
+
path = "/#{resource_name}/search/"
|
|
32
|
+
UserEngage.client.get(path, params)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def get_by_id(id)
|
|
36
|
+
path = "/#{resource_name}/#{id}/"
|
|
37
|
+
UserEngage.client.get(path)
|
|
38
|
+
end
|
|
39
|
+
|
|
24
40
|
def check_for_existing_resource!(response, params)
|
|
25
41
|
return if response.status == 200
|
|
42
|
+
|
|
26
43
|
raise(
|
|
27
44
|
UserEngage::ResourceNotFoundException,
|
|
28
45
|
"No resource with {#{params.inspect}} found!"
|
|
@@ -30,13 +47,17 @@ module UserEngage
|
|
|
30
47
|
end
|
|
31
48
|
|
|
32
49
|
def check_for_unsupported_params!(params)
|
|
33
|
-
|
|
34
|
-
|
|
50
|
+
if params.is_a?(Integer)
|
|
51
|
+
true
|
|
52
|
+
else
|
|
53
|
+
unsupported_params = params.keys - supported_find_params
|
|
54
|
+
return if unsupported_params.size.zero?
|
|
35
55
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
56
|
+
raise(
|
|
57
|
+
UserEngage::InvalidFindAttributeException,
|
|
58
|
+
"Unsupported parameter/s used: #{unsupported_params.join(', ')}"
|
|
59
|
+
)
|
|
60
|
+
end
|
|
40
61
|
end
|
|
41
62
|
end
|
|
42
63
|
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module UserEngage
|
|
4
|
+
module Operation
|
|
5
|
+
module UpdateAttributes
|
|
6
|
+
# Public: Updates attributes of the resource
|
|
7
|
+
#
|
|
8
|
+
# Params: attributes - A hash where
|
|
9
|
+
# the key is the name_std of the attribute to set and
|
|
10
|
+
# the value is the value to set
|
|
11
|
+
#
|
|
12
|
+
def update_attributes(attributes_hash)
|
|
13
|
+
update_remote_attributes!(attributes_hash) &&
|
|
14
|
+
update_local_attributes!(attributes_hash)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
#####################
|
|
18
|
+
## Private methods ##
|
|
19
|
+
#####################
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
# Privates: Generates the destination endpoint and
|
|
23
|
+
# calls it with POST and given attributes.
|
|
24
|
+
#
|
|
25
|
+
def update_remote_attributes!(attributes_hash)
|
|
26
|
+
path = "/#{resource_name}/#{id}/set_multiple_attributes/"
|
|
27
|
+
UserEngage.client.post(path, attributes_hash)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Private: Iterates through all attributes and
|
|
31
|
+
# sets it on the instance.
|
|
32
|
+
#
|
|
33
|
+
def update_local_attributes!(attributes_hash)
|
|
34
|
+
attributes_hash.each_pair do |attr_name, attr_value|
|
|
35
|
+
update_local_attribute!(attr_name, attr_value)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Private: Search for the resources attribute with the given name
|
|
40
|
+
# and set's it's attribute to the given value.
|
|
41
|
+
#
|
|
42
|
+
def update_local_attribute!(name, value)
|
|
43
|
+
attribute = attributes[:attributes].find do |attr|
|
|
44
|
+
attr.name_std.to_s.eql?(name.to_s)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
if attribute.nil?
|
|
48
|
+
new_attr = UserEngage::Attribute.new(value: value, name: name.to_s)
|
|
49
|
+
attributes[:attributes] << new_attr
|
|
50
|
+
else
|
|
51
|
+
attribute.attributes[:value] = value
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'user_engage/base_model'
|
|
4
|
+
require 'user_engage/errors'
|
|
5
|
+
|
|
6
|
+
module UserEngage
|
|
7
|
+
class ResourceCollection < BaseModel
|
|
8
|
+
################
|
|
9
|
+
## Attributes ##
|
|
10
|
+
################
|
|
11
|
+
attribute :base_class, Types::Class
|
|
12
|
+
attribute :count, Types::Integer
|
|
13
|
+
attribute :current_page, Types::Integer.default(1)
|
|
14
|
+
attribute :next, Types::String
|
|
15
|
+
attribute :previous, Types::String
|
|
16
|
+
attribute :results, Types::Array
|
|
17
|
+
|
|
18
|
+
######################
|
|
19
|
+
## Instance methods ##
|
|
20
|
+
######################
|
|
21
|
+
|
|
22
|
+
# Public: Transforms the results Hash to base_class instances
|
|
23
|
+
#
|
|
24
|
+
def transform_results!
|
|
25
|
+
@attributes[:results] = results.collect do |result|
|
|
26
|
+
base_class.new(result)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Public: Request next pages resources and increase the current_page.
|
|
31
|
+
# Throws an UserEngage::NoNextPageAvailable if no next page is available
|
|
32
|
+
#
|
|
33
|
+
def go_next!
|
|
34
|
+
check_page_availability!(:next)
|
|
35
|
+
|
|
36
|
+
response = UserEngage.client.get(self.next)
|
|
37
|
+
update_page_related_attributes!(response)
|
|
38
|
+
|
|
39
|
+
@attributes[:current_page] += 1
|
|
40
|
+
|
|
41
|
+
self
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Public: Request previous pages resources and increase the current_page.
|
|
45
|
+
# Throws an UserEngage::NoPreviousPageAvailable if no next page is available
|
|
46
|
+
#
|
|
47
|
+
def go_previous!
|
|
48
|
+
check_page_availability!(:previous)
|
|
49
|
+
|
|
50
|
+
response = UserEngage.client.get(previous)
|
|
51
|
+
update_page_related_attributes!(response)
|
|
52
|
+
|
|
53
|
+
@attributes[:current_page] -= 1
|
|
54
|
+
self
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Public: Iterates through whole collection and
|
|
58
|
+
# yield with each element.
|
|
59
|
+
# Goes to next page and continues to iterate,
|
|
60
|
+
# if a next page is still available
|
|
61
|
+
#
|
|
62
|
+
def each
|
|
63
|
+
loop do
|
|
64
|
+
results.each do |result|
|
|
65
|
+
yield(result)
|
|
66
|
+
end
|
|
67
|
+
go_next!
|
|
68
|
+
end
|
|
69
|
+
rescue UserEngage::NoNextPageAvailableException
|
|
70
|
+
true
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
#####################
|
|
74
|
+
## Private methods ##
|
|
75
|
+
#####################
|
|
76
|
+
private
|
|
77
|
+
|
|
78
|
+
# Private: Checks the given type of page availability.
|
|
79
|
+
# If not present, it raises an UserEngage::NoNextPageAvailable
|
|
80
|
+
# or NoPreviousPageAvailable
|
|
81
|
+
#
|
|
82
|
+
def check_page_availability!(type)
|
|
83
|
+
return unless @attributes[type.to_sym].nil?
|
|
84
|
+
|
|
85
|
+
raise(
|
|
86
|
+
type.eql?(:next) ?
|
|
87
|
+
UserEngage::NoNextPageAvailableException :
|
|
88
|
+
UserEngage::NoPreviousPageAvailableException,
|
|
89
|
+
"No #{type} page available"
|
|
90
|
+
)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Private: This parses given responses body's JSON,
|
|
94
|
+
# sets the collection attributes from that
|
|
95
|
+
# JSON response and transform the results array
|
|
96
|
+
# to a collection of base_class instances.
|
|
97
|
+
#
|
|
98
|
+
# Following attributes get set:
|
|
99
|
+
# * next
|
|
100
|
+
# * previous
|
|
101
|
+
# * results
|
|
102
|
+
def update_page_related_attributes!(response)
|
|
103
|
+
data = JSON.parse(response.body, symbolize_names: true)
|
|
104
|
+
@attributes[:next] = data[:next]
|
|
105
|
+
@attributes[:previous] = data[:previous]
|
|
106
|
+
@attributes[:results] = data[:results]
|
|
107
|
+
transform_results!
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
data/lib/user_engage/tag.rb
CHANGED
data/lib/user_engage/user.rb
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'user_engage/base_model'
|
|
4
|
+
require 'user_engage/operation/all'
|
|
5
|
+
require 'user_engage/operation/create'
|
|
2
6
|
require 'user_engage/operation/find'
|
|
3
7
|
require 'user_engage/operation/destroy'
|
|
8
|
+
require 'user_engage/operation/update_attributes'
|
|
4
9
|
|
|
5
10
|
require 'user_engage/attribute'
|
|
6
11
|
require 'user_engage/list'
|
|
@@ -11,8 +16,11 @@ module UserEngage
|
|
|
11
16
|
##############
|
|
12
17
|
## Includes ##
|
|
13
18
|
##############
|
|
19
|
+
extend Operation::All
|
|
20
|
+
extend Operation::Create
|
|
14
21
|
extend Operation::Find
|
|
15
22
|
include Operation::Destroy
|
|
23
|
+
include Operation::UpdateAttributes
|
|
16
24
|
|
|
17
25
|
################
|
|
18
26
|
## Attributes ##
|
|
@@ -22,6 +30,7 @@ module UserEngage
|
|
|
22
30
|
attribute :browser_language, Types::String
|
|
23
31
|
attribute :chat_id, Types::Integer
|
|
24
32
|
attribute :city, Types::String
|
|
33
|
+
attribute :companies, Types::Array.of(UserEngage::Company)
|
|
25
34
|
attribute :country, Types::String
|
|
26
35
|
attribute :created_at, Types::DateTime
|
|
27
36
|
attribute :email, Types::String
|
|
@@ -53,17 +62,22 @@ module UserEngage
|
|
|
53
62
|
attribute :updated_at, Types::DateTime
|
|
54
63
|
attribute :user_id, Types::Any
|
|
55
64
|
|
|
65
|
+
###################
|
|
66
|
+
## Class methods ##
|
|
67
|
+
###################
|
|
68
|
+
def self.resource_name
|
|
69
|
+
'users'
|
|
70
|
+
end
|
|
71
|
+
|
|
56
72
|
#####################
|
|
57
73
|
## Private methods ##
|
|
58
74
|
#####################
|
|
59
|
-
private_class_method
|
|
60
|
-
|
|
61
|
-
def self.supported_find_params
|
|
75
|
+
private_class_method def self.supported_find_params
|
|
62
76
|
%i[email key phone_number date]
|
|
63
77
|
end
|
|
64
78
|
|
|
65
|
-
def self.
|
|
66
|
-
|
|
79
|
+
private_class_method def self.required_params
|
|
80
|
+
%i[email]
|
|
67
81
|
end
|
|
68
82
|
end
|
|
69
83
|
end
|
data/lib/user_engage/version.rb
CHANGED
data/lib/user_engage.rb
CHANGED
data/user_engage.gemspec
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
|
|
2
|
-
lib = File.expand_path('
|
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
5
|
require 'user_engage/version'
|
|
5
6
|
|
|
@@ -28,9 +29,10 @@ Gem::Specification.new do |spec|
|
|
|
28
29
|
|
|
29
30
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
|
30
31
|
spec.add_development_dependency 'dotenv', '~> 2.2'
|
|
32
|
+
spec.add_development_dependency 'pry', '~> 0.11.3'
|
|
31
33
|
spec.add_development_dependency 'rake', '~> 10.0'
|
|
32
34
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
33
|
-
spec.add_development_dependency 'rubocop', '~> 0.
|
|
35
|
+
spec.add_development_dependency 'rubocop', '~> 0.59'
|
|
34
36
|
spec.add_development_dependency 'vcr', '~> 4.0'
|
|
35
37
|
spec.add_development_dependency 'webmock', '~> 3.3'
|
|
36
38
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: user_engage
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Markus Schwed
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-
|
|
11
|
+
date: 2018-10-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: dry-struct
|
|
@@ -66,6 +66,20 @@ dependencies:
|
|
|
66
66
|
- - "~>"
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
68
|
version: '2.2'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: pry
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: 0.11.3
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: 0.11.3
|
|
69
83
|
- !ruby/object:Gem::Dependency
|
|
70
84
|
name: rake
|
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -100,14 +114,14 @@ dependencies:
|
|
|
100
114
|
requirements:
|
|
101
115
|
- - "~>"
|
|
102
116
|
- !ruby/object:Gem::Version
|
|
103
|
-
version: '0.
|
|
117
|
+
version: '0.59'
|
|
104
118
|
type: :development
|
|
105
119
|
prerelease: false
|
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
|
107
121
|
requirements:
|
|
108
122
|
- - "~>"
|
|
109
123
|
- !ruby/object:Gem::Version
|
|
110
|
-
version: '0.
|
|
124
|
+
version: '0.59'
|
|
111
125
|
- !ruby/object:Gem::Dependency
|
|
112
126
|
name: vcr
|
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -153,7 +167,6 @@ files:
|
|
|
153
167
|
- Gemfile
|
|
154
168
|
- Gemfile.lock
|
|
155
169
|
- LICENSE.txt
|
|
156
|
-
- NetrwTreeListing 3
|
|
157
170
|
- README.md
|
|
158
171
|
- Rakefile
|
|
159
172
|
- TODO.md
|
|
@@ -163,11 +176,16 @@ files:
|
|
|
163
176
|
- lib/user_engage/attribute.rb
|
|
164
177
|
- lib/user_engage/base_model.rb
|
|
165
178
|
- lib/user_engage/client.rb
|
|
179
|
+
- lib/user_engage/company.rb
|
|
166
180
|
- lib/user_engage/configuration.rb
|
|
167
181
|
- lib/user_engage/errors.rb
|
|
168
182
|
- lib/user_engage/list.rb
|
|
183
|
+
- lib/user_engage/operation/all.rb
|
|
184
|
+
- lib/user_engage/operation/create.rb
|
|
169
185
|
- lib/user_engage/operation/destroy.rb
|
|
170
186
|
- lib/user_engage/operation/find.rb
|
|
187
|
+
- lib/user_engage/operation/update_attributes.rb
|
|
188
|
+
- lib/user_engage/resource_collection.rb
|
|
171
189
|
- lib/user_engage/tag.rb
|
|
172
190
|
- lib/user_engage/user.rb
|
|
173
191
|
- lib/user_engage/version.rb
|
|
@@ -192,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
192
210
|
version: '0'
|
|
193
211
|
requirements: []
|
|
194
212
|
rubyforge_project:
|
|
195
|
-
rubygems_version: 2.7.
|
|
213
|
+
rubygems_version: 2.7.7
|
|
196
214
|
signing_key:
|
|
197
215
|
specification_version: 4
|
|
198
216
|
summary: NOT READY YET!! - Ruby bindings for the UserEngage API
|
data/NetrwTreeListing 3
DELETED
|
File without changes
|