followanalytics 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b41934781c862369956d4d7a40c713614bf0177
4
- data.tar.gz: 16557e7218ad370a1ea10b11cb8da8eb29f9d402
3
+ metadata.gz: d6353d9c2d7408f04ab06228995da32e9989b3af
4
+ data.tar.gz: de852e6118309e40391a3e7c395789bdcbda9a13
5
5
  SHA512:
6
- metadata.gz: 52b11d4ba47c19c50eb1951ff0c56ccf3461829c5ba7a0092c6355f1af7398d71841767938be01f2d284c298aa637bd44148970fd5881fee5ef490a80b06587c
7
- data.tar.gz: 11c65c49d96f7a0622167845ec3cc794afabb5865f37b6c5db7c18c7f38c53d029907f3d5b11859fafec49da2316fa0ad71c973e55e72ad5963bd25be6a3b5e3
6
+ metadata.gz: 2e352cb6efc54eabc4477460928718841b5543d57e53380ba4204b68ceff4b9182c8ac92647de95766b8ccf50ee2f8e300c6c66d4cb43fd2e66190f915e85d22
7
+ data.tar.gz: f67dc08860b90aed21842519b4fe4bf30c83ad8662d73da2ceaef3e0b70ed57c0b028b6c17bb116d73cc31e7d4b6aabab552181b16a4449bc0d988ec41238a4a
data/README.md CHANGED
@@ -26,10 +26,41 @@ Or install it yourself as:
26
26
  # In an initializer:
27
27
  Followanalytics.configure do |config|
28
28
  config.api_key = ENV['FA_API_KEY']
29
- config.api_base_url = ENV['FA_API_BASE_URL'] # Optional, defaults to "https://api.follow-apps.com".
30
29
  end
31
30
  ```
32
31
 
32
+ ### Using the attributes
33
+
34
+ #### Create a client
35
+ ```ruby
36
+ client = Followanalytics::Attributes::Client.new(sor_identifier)
37
+ ```
38
+
39
+ #### Setting a value to a predefined attribute
40
+ ```ruby
41
+ client.set_first_name("Tim", "customer-00001")
42
+ ```
43
+
44
+ #### Setting a value to a custom attribute
45
+ ```ruby
46
+ client.set_value("apple", "favorite_fruit", "customer-00001")
47
+ ```
48
+
49
+ #### Unsetting an attribute value
50
+ ```ruby
51
+ client.unset_value("favorite_fruit", "customer-00001")
52
+ ```
53
+
54
+ #### Adding a value to an attribute of type set
55
+ ```ruby
56
+ client.add_set_value("strawberry", "fruit_salad", "customer-00001")
57
+ ```
58
+
59
+ #### Removing a value to an attribute of type set
60
+ ```ruby
61
+ client.remove_set_value("strawberry", "fruit_salad", "customer-00001")
62
+ ```
63
+
33
64
  ## Development
34
65
 
35
66
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -5,6 +5,7 @@ require 'followanalytics/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "followanalytics"
8
+ spec.email = "technique@followanalytics.com"
8
9
  spec.version = Followanalytics::VERSION
9
10
  spec.required_ruby_version = '>= 2.0.0'
10
11
  spec.authors = ["José Carlos Joaquim"]
@@ -14,27 +14,57 @@ module Followanalytics
14
14
  profile_picture
15
15
  ).freeze
16
16
 
17
+ # Initializes the Attributes client.
18
+ #
19
+ # @param sor_identifier [String] The System of Record we wish to set
20
+ # attributes to.
21
+ # @raise [Followanalytics::Error] When the System of Record is not
22
+ # defined.
17
23
  def initialize(sor_identifier)
18
24
  raise Followanalytics::Error, MISSING_SOR if sor_identifier.nil?
19
25
  @sor_identifier = sor_identifier
20
26
  end
21
27
 
22
28
  PREDEFINED_ATTRIBUTE_KEYS.each do |attribute_key|
29
+ # TODO: Find a way to document these.
23
30
  define_method("set_#{attribute_key}") do |value, customer_id|
24
31
  set_value(value, attribute_key, customer_id)
25
32
  end
26
33
  end
27
34
 
35
+ # Set one value for a customer.
36
+ #
37
+ # @param value The value to set.
38
+ # @param key The key of the attribute.
39
+ # @param customer_id The customer we want to set the attribute to.
40
+ #
41
+ # @example Set the value "apple" to the attribute with the key "favorite_fruit" for the customer "tim"
42
+ # client.set_value("apple", "favorite_fruit", "tim")
28
43
  def set_value(value, key, customer_id)
29
44
  hash = attribute_hash(value, key, customer_id)
30
45
  send_attributes(hash)
31
46
  end
32
47
 
48
+ # Unset one value for a customer.
49
+ #
50
+ # @param key The key of the attribute.
51
+ # @param customer_id The customer we want to unset the attribute to.
52
+ #
53
+ # @example Unset the value "apple" to the attribute with the key "favorite_fruit" for the customer "tim"
54
+ # client.unset_value("favorite_fruit", "tim")
33
55
  def unset_value(key, customer_id)
34
56
  hash = attribute_hash(nil, key, customer_id)
35
57
  send_attributes(hash)
36
58
  end
37
59
 
60
+ # Add a value to an attribute of type set.
61
+ #
62
+ # @param value The value to add to the set.
63
+ # @param key The key of the set attribute.
64
+ # @param customer_id The customer we want to unset the attribute to.
65
+ #
66
+ # @example Add the value "strawberry" to the set attribute with the key "fruit_salad" for the customer "tim"
67
+ # client.add_set_value("strawberry", "fruit_salad", "tim")
38
68
  def add_set_value(value, key, customer_id)
39
69
  hash = attribute_hash(value, key, customer_id).tap do |hsh|
40
70
  hsh['action_type'] = 'ADD'
@@ -42,6 +72,14 @@ module Followanalytics
42
72
  send_attributes(hash)
43
73
  end
44
74
 
75
+ # Remove a value to an attribute of type set.
76
+ #
77
+ # @param value The value to add to the set.
78
+ # @param key The key of the set attribute.
79
+ # @param customer_id The customer we want to unset the attribute to.
80
+ #
81
+ # @example Remove the value "strawberry" to the set attribute with the key "fruit_salad" for the customer "tim"
82
+ # client.remove_set_value("strawberry", "fruit_salad", "tim")
45
83
  def remove_set_value(value, key, customer_id)
46
84
  hash = attribute_hash(value, key, customer_id).tap do |hsh|
47
85
  hsh['action_type'] = 'REMOVE'
@@ -2,9 +2,16 @@ require 'oj'
2
2
 
3
3
  module Followanalytics
4
4
  class Error < StandardError
5
+ attr_accessor :original_exception
6
+
7
+ def initialize(message, original_exception = nil)
8
+ super(message)
9
+ @original_exception = original_exception
10
+ end
11
+
5
12
  def self.from_rest_client(exception)
6
13
  body = Oj.load(exception.response.body)
7
- self.new(body['message'])
14
+ self.new(body['message'], exception)
8
15
  end
9
16
  end
10
17
  end
@@ -1,3 +1,3 @@
1
1
  module Followanalytics
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: followanalytics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - José Carlos Joaquim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-31 00:00:00.000000000 Z
11
+ date: 2016-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '2.17'
83
83
  description: Ruby client for the FollowAnalytics API.
84
- email:
84
+ email: technique@followanalytics.com
85
85
  executables: []
86
86
  extensions: []
87
87
  extra_rdoc_files: []
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  version: '0'
122
122
  requirements: []
123
123
  rubyforge_project:
124
- rubygems_version: 2.6.2
124
+ rubygems_version: 2.4.5.1
125
125
  signing_key:
126
126
  specification_version: 4
127
127
  summary: Ruby client for the FollowAnalytics API.