followanalytics 0.1.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 +7 -0
- data/.gitignore +50 -0
- data/.rspec +2 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +73 -0
- data/LICENSE.txt +21 -0
- data/README.md +47 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/followanalytics.gemspec +28 -0
- data/lib/followanalytics.rb +31 -0
- data/lib/followanalytics/api.rb +7 -0
- data/lib/followanalytics/attributes.rb +83 -0
- data/lib/followanalytics/error.rb +10 -0
- data/lib/followanalytics/version.rb +3 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8b41934781c862369956d4d7a40c713614bf0177
|
4
|
+
data.tar.gz: 16557e7218ad370a1ea10b11cb8da8eb29f9d402
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 52b11d4ba47c19c50eb1951ff0c56ccf3461829c5ba7a0092c6355f1af7398d71841767938be01f2d284c298aa637bd44148970fd5881fee5ef490a80b06587c
|
7
|
+
data.tar.gz: 11c65c49d96f7a0622167845ec3cc794afabb5865f37b6c5db7c18c7f38c53d029907f3d5b11859fafec49da2316fa0ad71c973e55e72ad5963bd25be6a3b5e3
|
data/.gitignore
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
*.bridgesupport
|
21
|
+
build-iPhoneOS/
|
22
|
+
build-iPhoneSimulator/
|
23
|
+
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
25
|
+
#
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
29
|
+
#
|
30
|
+
# vendor/Pods/
|
31
|
+
|
32
|
+
## Documentation cache and generated files:
|
33
|
+
/.yardoc/
|
34
|
+
/_yardoc/
|
35
|
+
/doc/
|
36
|
+
/rdoc/
|
37
|
+
|
38
|
+
## Environment normalization:
|
39
|
+
/.bundle/
|
40
|
+
/vendor/bundle
|
41
|
+
/lib/bundler/man/
|
42
|
+
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
45
|
+
# Gemfile.lock
|
46
|
+
# .ruby-version
|
47
|
+
# .ruby-gemset
|
48
|
+
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
50
|
+
.rvmrc
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
followanalytics (0.1.0)
|
5
|
+
oj (~> 2.17)
|
6
|
+
rest-client (~> 2.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ast (2.3.0)
|
12
|
+
byebug (9.0.5)
|
13
|
+
diff-lcs (1.2.5)
|
14
|
+
domain_name (0.5.20160615)
|
15
|
+
unf (>= 0.0.5, < 1.0.0)
|
16
|
+
faker (1.6.6)
|
17
|
+
i18n (~> 0.5)
|
18
|
+
http-cookie (1.0.2)
|
19
|
+
domain_name (~> 0.5)
|
20
|
+
i18n (0.7.0)
|
21
|
+
mime-types (3.1)
|
22
|
+
mime-types-data (~> 3.2015)
|
23
|
+
mime-types-data (3.2016.0521)
|
24
|
+
netrc (0.11.0)
|
25
|
+
oj (2.17.3)
|
26
|
+
parser (2.3.1.2)
|
27
|
+
ast (~> 2.2)
|
28
|
+
powerpack (0.1.1)
|
29
|
+
rainbow (2.1.0)
|
30
|
+
rake (10.5.0)
|
31
|
+
rest-client (2.0.0)
|
32
|
+
http-cookie (>= 1.0.2, < 2.0)
|
33
|
+
mime-types (>= 1.16, < 4.0)
|
34
|
+
netrc (~> 0.8)
|
35
|
+
rspec (3.5.0)
|
36
|
+
rspec-core (~> 3.5.0)
|
37
|
+
rspec-expectations (~> 3.5.0)
|
38
|
+
rspec-mocks (~> 3.5.0)
|
39
|
+
rspec-core (3.5.2)
|
40
|
+
rspec-support (~> 3.5.0)
|
41
|
+
rspec-expectations (3.5.0)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.5.0)
|
44
|
+
rspec-mocks (3.5.0)
|
45
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
+
rspec-support (~> 3.5.0)
|
47
|
+
rspec-support (3.5.0)
|
48
|
+
rubocop (0.42.0)
|
49
|
+
parser (>= 2.3.1.1, < 3.0)
|
50
|
+
powerpack (~> 0.1)
|
51
|
+
rainbow (>= 1.99.1, < 3.0)
|
52
|
+
ruby-progressbar (~> 1.7)
|
53
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
54
|
+
ruby-progressbar (1.8.1)
|
55
|
+
unf (0.1.4)
|
56
|
+
unf_ext
|
57
|
+
unf_ext (0.0.7.2)
|
58
|
+
unicode-display_width (1.1.0)
|
59
|
+
|
60
|
+
PLATFORMS
|
61
|
+
ruby
|
62
|
+
|
63
|
+
DEPENDENCIES
|
64
|
+
bundler (~> 1.12)
|
65
|
+
byebug
|
66
|
+
faker
|
67
|
+
followanalytics!
|
68
|
+
rake (~> 10.0)
|
69
|
+
rspec
|
70
|
+
rubocop
|
71
|
+
|
72
|
+
BUNDLED WITH
|
73
|
+
1.12.5
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 José Carlos Joaquim
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Followanalytics
|
2
|
+
|
3
|
+
Welcome to the FollowAnalytics gem. It will allow to to use the FollowAnalytics Platform API
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'followanalytics'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install followanalytics
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Configuration
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
# In an initializer:
|
27
|
+
Followanalytics.configure do |config|
|
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
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
## Development
|
34
|
+
|
35
|
+
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.
|
36
|
+
|
37
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/followanalytics.
|
42
|
+
|
43
|
+
|
44
|
+
## License
|
45
|
+
|
46
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
47
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "followanalytics"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'followanalytics/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "followanalytics"
|
8
|
+
spec.version = Followanalytics::VERSION
|
9
|
+
spec.required_ruby_version = '>= 2.0.0'
|
10
|
+
spec.authors = ["José Carlos Joaquim"]
|
11
|
+
spec.summary = %q{Ruby client for the FollowAnalytics API.}
|
12
|
+
spec.description = %q{Ruby client for the FollowAnalytics API.}
|
13
|
+
spec.homepage = "https://github.com/followanalytics/fa-api-gem"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
|
26
|
+
spec.add_dependency 'rest-client', '~> 2.0'
|
27
|
+
spec.add_dependency 'oj', '~> 2.17'
|
28
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "followanalytics/attributes"
|
2
|
+
require "followanalytics/version"
|
3
|
+
require 'followanalytics/error'
|
4
|
+
|
5
|
+
module Followanalytics
|
6
|
+
class << self
|
7
|
+
attr_writer :configuration
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.configuration
|
11
|
+
@configuration ||= Configuration.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.configure
|
15
|
+
yield(configuration)
|
16
|
+
end
|
17
|
+
|
18
|
+
class Configuration
|
19
|
+
attr_accessor :api_key
|
20
|
+
attr_accessor :api_base_url
|
21
|
+
attr_accessor :attribute_base_url
|
22
|
+
|
23
|
+
DEFAULT_API_BASE_URL = 'https://api.follow-apps.com'
|
24
|
+
DEFAULT_ATTRIBUTES_BASE_URL = 'https://sor.follow-apps.com'
|
25
|
+
|
26
|
+
def initialize
|
27
|
+
@api_base_url = DEFAULT_API_BASE_URL
|
28
|
+
@attribute_base_url = DEFAULT_ATTRIBUTES_BASE_URL
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'oj'
|
3
|
+
|
4
|
+
module Followanalytics
|
5
|
+
module Attributes
|
6
|
+
class Client
|
7
|
+
attr_accessor :sor_identifier
|
8
|
+
|
9
|
+
MISSING_SOR = 'Missing System of Record identifier.'.freeze
|
10
|
+
MISSING_API_KEY = 'Missing api key in configuration.'.freeze
|
11
|
+
|
12
|
+
PREDEFINED_ATTRIBUTE_KEYS = %w(
|
13
|
+
first_name last_name email date_of_birth gender country city region
|
14
|
+
profile_picture
|
15
|
+
).freeze
|
16
|
+
|
17
|
+
def initialize(sor_identifier)
|
18
|
+
raise Followanalytics::Error, MISSING_SOR if sor_identifier.nil?
|
19
|
+
@sor_identifier = sor_identifier
|
20
|
+
end
|
21
|
+
|
22
|
+
PREDEFINED_ATTRIBUTE_KEYS.each do |attribute_key|
|
23
|
+
define_method("set_#{attribute_key}") do |value, customer_id|
|
24
|
+
set_value(value, attribute_key, customer_id)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_value(value, key, customer_id)
|
29
|
+
hash = attribute_hash(value, key, customer_id)
|
30
|
+
send_attributes(hash)
|
31
|
+
end
|
32
|
+
|
33
|
+
def unset_value(key, customer_id)
|
34
|
+
hash = attribute_hash(nil, key, customer_id)
|
35
|
+
send_attributes(hash)
|
36
|
+
end
|
37
|
+
|
38
|
+
def add_set_value(value, key, customer_id)
|
39
|
+
hash = attribute_hash(value, key, customer_id).tap do |hsh|
|
40
|
+
hsh['action_type'] = 'ADD'
|
41
|
+
end
|
42
|
+
send_attributes(hash)
|
43
|
+
end
|
44
|
+
|
45
|
+
def remove_set_value(value, key, customer_id)
|
46
|
+
hash = attribute_hash(value, key, customer_id).tap do |hsh|
|
47
|
+
hsh['action_type'] = 'REMOVE'
|
48
|
+
end
|
49
|
+
send_attributes(hash)
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def attributes_url
|
55
|
+
"#{Followanalytics.configuration.attribute_base_url}/api/attribute_values"
|
56
|
+
end
|
57
|
+
|
58
|
+
def attribute_hash(value, key, customer_id)
|
59
|
+
{
|
60
|
+
"attribute_key" => key,
|
61
|
+
"attribute_value" => value,
|
62
|
+
"customer_id" => customer_id,
|
63
|
+
"customer_id_type" => "user_id"
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
def send_attributes(hash)
|
68
|
+
api_key = Followanalytics.configuration.api_key
|
69
|
+
raise Followanalytics::Error, MISSING_API_KEY if api_key.nil?
|
70
|
+
|
71
|
+
params = Oj.dump({
|
72
|
+
"sor" => @sor_identifier,
|
73
|
+
"api_key" => api_key,
|
74
|
+
"customer_attribute_values" => [hash]
|
75
|
+
})
|
76
|
+
|
77
|
+
response = RestClient.post(attributes_url, params, content_type: :json)
|
78
|
+
rescue RestClient::Exception => exception
|
79
|
+
raise Followanalytics::Error.from_rest_client(exception)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: followanalytics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- José Carlos Joaquim
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rest-client
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: oj
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.17'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.17'
|
83
|
+
description: Ruby client for the FollowAnalytics API.
|
84
|
+
email:
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- ".gitignore"
|
90
|
+
- ".rspec"
|
91
|
+
- Gemfile
|
92
|
+
- Gemfile.lock
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/console
|
97
|
+
- bin/setup
|
98
|
+
- followanalytics.gemspec
|
99
|
+
- lib/followanalytics.rb
|
100
|
+
- lib/followanalytics/api.rb
|
101
|
+
- lib/followanalytics/attributes.rb
|
102
|
+
- lib/followanalytics/error.rb
|
103
|
+
- lib/followanalytics/version.rb
|
104
|
+
homepage: https://github.com/followanalytics/fa-api-gem
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 2.0.0
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.6.2
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Ruby client for the FollowAnalytics API.
|
128
|
+
test_files: []
|