malartu 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1de880b32bdae8cec4dfe3160b1632e633153be7
4
+ data.tar.gz: 99335adf08e0d7affbd7beffddc3df038fca30eb
5
+ SHA512:
6
+ metadata.gz: ccc1f2d3a01e5a718e11c2b1dde752daa600627e866cf60da8bb0c8b2818a6f0430f6ef0b33071827504a3f8469a93fc93dbe25454934bf28e6c9c7df1ec90e0
7
+ data.tar.gz: 16cff108e55cf328b465a12da36fcad49762cf2137f09dacb7c6e20b112f4619c7ae9d12d9b732eae11d2baff3f08ed011fb6ad2d0c8d07bdd38a8778ce039e5
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in malartu.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'pry'
8
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 david-richey
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.
@@ -0,0 +1,51 @@
1
+ # Malartu
2
+
3
+ Malartu API makes it easy to interact with [Malartu](https://www.malartu.co/). This gem is a ruby wrapper for the [Malartu API](https://app.malartu.co/docs/api).
4
+
5
+ Some examples of what you can do with the Malartu API:
6
+
7
+ * Track custom metrics to be aggregated into your other integrations data. See what [integration Malartu provides](https://www.malartu.co/integrations/)
8
+ * View your aggregated metrics
9
+ * View your reports created in Malartu
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'malartu'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install malartu
26
+
27
+ ## Usage
28
+
29
+ Set your apikey
30
+ `Malartu.apikey = 'XXXXX-XXXXXXXXXXXXXXX'`
31
+
32
+ Start extending your usage with the Malartu API
33
+ ```
34
+ Malartu::Metric.uids # valid uids you are tracking in Malartu
35
+ Malartu::Metric.list(starting: (Date.today - 5.days).to_s, ending: Date.today.to_s, uids: ['arr', 'mrr'])
36
+ Malartu::Tracking::Data.list(starting: (Date.today - 5.days).to_s, ending: Date.today.to_s)
37
+ Malartu::Schedule.list
38
+ ```
39
+
40
+
41
+ ## Development
42
+
43
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/davidrichey/malartu-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
48
+
49
+ ## License
50
+
51
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "malartu"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,81 @@
1
+ require 'http'
2
+
3
+ require 'malartu/malartu_object'
4
+ require 'malartu/connection'
5
+ require 'malartu/error'
6
+ require 'malartu/metric'
7
+ require 'malartu/portfolio'
8
+ require 'malartu/schedule'
9
+ require 'malartu/tracking'
10
+ require 'malartu/tracking/data'
11
+ require 'malartu/version'
12
+
13
+ module Malartu
14
+ API_VERSION = 'v0'.freeze
15
+ API_PATH = 'https://api.malartu.co'.freeze
16
+ class << self
17
+ attr_accessor :apikey, :api_version, :topics
18
+
19
+ def request(method, path, params = {}, _headers = {})
20
+ url = "#{base_path}#{path}"
21
+ req_params = case method.to_s
22
+ when 'get'
23
+ { params: params.merge(auth_params) }
24
+ else
25
+ { json: params.merge(auth_params) }
26
+ end
27
+ response = HTTP.send(method, url, req_params)
28
+ check_for_errors(response, params.merge(auth_params))
29
+ JSON.parse(response.body)
30
+ end
31
+
32
+ def auth_params
33
+ fail 'No apikey present. Set it with `Malartu.apikey =`' if apikey.nil?
34
+ { apikey: apikey }
35
+ end
36
+
37
+ def base_path
38
+ "#{API_PATH}/#{version}"
39
+ end
40
+
41
+ def version
42
+ api_version || API_VERSION
43
+ end
44
+
45
+ def check_for_errors(response, params)
46
+ case response.code
47
+ when 401
48
+ fail Malartu::Error::AuthorizationError.new(
49
+ message: 'Credentials do not match',
50
+ parameters: {
51
+ apikey: params[:apikey]
52
+ },
53
+ json_body: JSON.parse(response.body)
54
+ )
55
+ when 404
56
+ fail Malartu::Error::RecordNotFoundError.new(
57
+ message: 'Record Not Found',
58
+ parameters: {
59
+ id: params[:id],
60
+ model: params[:model]
61
+ },
62
+ json_body: JSON.parse(response.body)
63
+ )
64
+ when 429
65
+ fail Malartu::Error::RateLimitError.new(
66
+ message: 'Rate Limited',
67
+ parameters: {
68
+ apikey: params[:apikey]
69
+ },
70
+ json_body: JSON.parse(response.body)
71
+ )
72
+ when 500
73
+ fail Malartu::Error::ServerError.new(
74
+ message: 'Server Error',
75
+ parameters: params,
76
+ json_body: JSON.parse(response.body)
77
+ )
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,23 @@
1
+ module Malartu
2
+ # A connection is what ties together a company and a portfolios
3
+ class Connection < MalartuObject
4
+ def self.list
5
+ res = Malartu.request('get', '/kpi/connections')
6
+ res['connections'].map do |connection|
7
+ Malartu::Schedule.new(connection)
8
+ end
9
+ end
10
+
11
+ def self.metrics(id, starting: nil, ending: DateTime.now.to_s, grain: nil, timezone: "UTC", uids: [])
12
+ uids = uids.join(',')
13
+ params = {
14
+ start_date: starting,
15
+ end_date: ending,
16
+ grain: grain,
17
+ timezone: timezone,
18
+ uids: uids
19
+ }.select { |_, value| !value.nil? }
20
+ Malartu.request('get', "/kpi/connections/#{1}/metrics", params)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,25 @@
1
+ module Malartu
2
+ module Error
3
+ class MalartuError < StandardError
4
+ attr_reader :message, :parameters, :json_reponse
5
+
6
+ def initialize(message: nil, parameters: nil, json_body: nil)
7
+ @message = message
8
+ @parameters = parameters
9
+ @json_body = json_body
10
+ end
11
+ end
12
+
13
+ class AuthorizationError < MalartuError
14
+ end
15
+
16
+ class RateLimitError < MalartuError
17
+ end
18
+
19
+ class RecordNotFoundError < MalartuError
20
+ end
21
+
22
+ class ServerError < MalartuError
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ module Malartu
2
+ class MalartuObject
3
+ attr_accessor :json
4
+ def initialize(json)
5
+ json.each do |k, v|
6
+ define_singleton_method(k) { v }
7
+ end
8
+ @json = json
9
+ end
10
+
11
+ def self.paginate?(response)
12
+ page = response['page'].to_i
13
+ limit = response['limit'].to_i
14
+ found = response['found'].to_i
15
+ count = response['count'].to_i
16
+ ((page - 1) * limit) + count < found
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ module Malartu
2
+ # Metrics is how Malartu tracks data from various sources
3
+ class Metric < MalartuObject
4
+ def self.uids
5
+ Malartu.request('get', '/kpi/metric/uids')['valid_metric_uids']
6
+ end
7
+
8
+ def self.list(starting: nil, ending: Date.today.to_s, grain: nil, timezone: 'UTC', uids: [])
9
+ uids = uids.join(',')
10
+ params = {
11
+ start_date: starting,
12
+ end_date: ending,
13
+ grain: grain,
14
+ timezone: timezone,
15
+ uids: uids
16
+ }.select { |_, value| !value.nil? }
17
+ Malartu.request('get', '/kpi/metrics', params)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,27 @@
1
+ module Malartu
2
+ # A portfolio is how groups track companies within Malartu
3
+ class Portfolio < MalartuObject
4
+ attr_accessor :connections, :path
5
+ def initialize(json)
6
+ super
7
+ define_singleton_method('connections') do
8
+ json['connections'].map do |c|
9
+ Malartu::Connection.new(c)
10
+ end
11
+ end if json['connections']
12
+ define_singleton_method('path') { json['path'] || "/v0/kpi/portfolios/#{sid}" }
13
+ end
14
+
15
+ def self.find(sid)
16
+ res = Malartu.request('get', "/kpi/portfolios/#{sid}")
17
+ Malartu::Portfolio.new(res)
18
+ end
19
+
20
+ def self.list
21
+ res = Malartu.request('get', '/kpi/portfolios')
22
+ res['portfolios'].map do |schedule|
23
+ Malartu::Portfolio.new(schedule)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,24 @@
1
+ module Malartu
2
+ # A schedule is what tells Malartu when to aggregate the data
3
+ class Schedule < MalartuObject
4
+ def self.find(id = 'api')
5
+ res = Malartu.request('get', "/kpi/schedules/#{id}")
6
+ Malartu::Schedule.new(res)
7
+ end
8
+
9
+ def self.list
10
+ res = Malartu.request('get', '/kpi/schedules')
11
+ res['schedules'].map do |schedule|
12
+ Malartu::Schedule.new(schedule)
13
+ end
14
+ end
15
+
16
+ def self.update(id = 'api', active: false)
17
+ fail 'Invalid ID' unless id == 'api'
18
+ params = {}
19
+ params[:active] = active unless active.nil?
20
+ res = Malartu.request('patch', "/kpi/schedules/#{id}", params)
21
+ Malartu::Schedule.new(res)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,4 @@
1
+ module Malartu
2
+ module Tracking
3
+ end
4
+ end
@@ -0,0 +1,43 @@
1
+ module Malartu
2
+ module Tracking
3
+ # Tracking::Data lets you store data is the Malartu system
4
+ class Data < MalartuObject
5
+ def self.create(topic: nil, value: 1)
6
+ fail 'No topic' if topic.nil?
7
+ res = Malartu.request('post', '/kpi/tracking/data', topic: topic, value: value)
8
+ Malartu::Tracking::Data.new(res)
9
+ end
10
+
11
+ def self.find(id)
12
+ fail 'No ID given' if id.nil?
13
+ path = "/kpi/tracking/data/#{id}"
14
+ res = Malartu.request('get', path)
15
+ Malartu::Tracking::Data.new(res)
16
+ end
17
+
18
+ def self.list(starting:, ending:, page: 1, paginate: false, topic: nil)
19
+ params = { starting: starting, ending: ending, topic: topic, page: page }.select { |_, value| !value.nil? }
20
+ res = Malartu.request('get', '/kpi/tracking/data', params)
21
+ data = res['data'].map do |datum|
22
+ Malartu::Tracking::Data.new(datum)
23
+ end
24
+ page = res["page"].to_i
25
+ return data unless paginate?(res)
26
+ # Paginated requests
27
+ res = Malartu.request('get', '/kpi/tracking/data', params.merge(page: page + 1))
28
+ data + res['data']
29
+ end
30
+
31
+ def self.update(id, topic: nil, value: 1)
32
+ fail 'No Topic' if topic.nil?
33
+ params = {}
34
+ params[:topic] = topic unless topic.nil?
35
+ params[:value] = value unless value.nil?
36
+ fail 'No parameters to send' if params == {}
37
+ path = "/kpi/tracking/data/#{id}"
38
+ res = Malartu.request('patch', path, params)
39
+ Malartu::Tracking::Data.new(res)
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module Malartu
2
+ VERSION = '0.1.3'.freeze
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'malartu/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'malartu'
8
+ spec.version = Malartu::VERSION
9
+ spec.authors = ['david-richey']
10
+ spec.email = ['david.richey@validic.com']
11
+
12
+ spec.summary = %q{Wrapper for Malartu API}
13
+ spec.description = %q{Ruby Wrapper for Malartu API}
14
+ spec.homepage = 'https://app.malartu.co/docs/api'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.10'
23
+ spec.add_development_dependency 'rspec', '~> 3.1'
24
+ spec.add_development_dependency 'webmock', '~> 3.0'
25
+ spec.add_dependency 'http', '~> 3.0'
26
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: malartu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - david-richey
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-20 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
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: http
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Ruby Wrapper for Malartu API
70
+ email:
71
+ - david.richey@validic.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - lib/malartu.rb
87
+ - lib/malartu/connection.rb
88
+ - lib/malartu/error.rb
89
+ - lib/malartu/malartu_object.rb
90
+ - lib/malartu/metric.rb
91
+ - lib/malartu/portfolio.rb
92
+ - lib/malartu/schedule.rb
93
+ - lib/malartu/tracking.rb
94
+ - lib/malartu/tracking/data.rb
95
+ - lib/malartu/version.rb
96
+ - malartu.gemspec
97
+ homepage: https://app.malartu.co/docs/api
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.6.13
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Wrapper for Malartu API
121
+ test_files: []