flurry 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/lib/flurry/configuration.rb +11 -0
- data/lib/flurry/helper.rb +24 -0
- data/lib/flurry/request.rb +96 -0
- data/lib/flurry/version.rb +3 -0
- data/lib/flurry.rb +25 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aab9d43586ace9b91f12ef33efe629a925b6965615760ae91302574330bba5e6
|
4
|
+
data.tar.gz: aad2af4110cd6fa68efaad1cd5c9e8ca886d2248684d1bc1c404c755c3ac5363
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e515c93beb93060111cb0b87355b08de981d688f258017a697a5c1591ed7950e5c6aa923431c25f41113807d7dcc43ead3d2ab2ada24155beed0518abfdd0af1
|
7
|
+
data.tar.gz: 1d7858cb57f6a9e14a7d3484ee9eec409565777a881d270eb33c6debba90afdd487b0a7e39571ad6ae22d8bec0346590b11530a90a0cc46dbb8af101b2f2660f
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Roger Bagué Martí
|
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,24 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module Flurry
|
4
|
+
# Helper methods used across the library
|
5
|
+
module Helper
|
6
|
+
private
|
7
|
+
|
8
|
+
def camelize(string)
|
9
|
+
string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { $&.downcase }
|
10
|
+
string.gsub(%r{(?:_|(/))([a-z\d]*)}) do
|
11
|
+
"#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}"
|
12
|
+
end.gsub('/', '::')
|
13
|
+
end
|
14
|
+
|
15
|
+
def datetime?(value)
|
16
|
+
value.respond_to?(:strftime)
|
17
|
+
end
|
18
|
+
|
19
|
+
def tomorrow(date)
|
20
|
+
tomorrow = Date.parse(date.to_s) if date.is_a?(Time)
|
21
|
+
(tomorrow || date) + 1
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'flurry/helper'
|
3
|
+
|
4
|
+
module Flurry
|
5
|
+
class Request # :nodoc:
|
6
|
+
include HTTParty
|
7
|
+
include Helper
|
8
|
+
|
9
|
+
base_uri 'https://api-metrics.flurry.com/public/v1/data'
|
10
|
+
|
11
|
+
def initialize(table, group_by)
|
12
|
+
raise ArgumentError, 'table must be non nil' if table.nil?
|
13
|
+
|
14
|
+
@table = table
|
15
|
+
@grain = group_by || :day
|
16
|
+
end
|
17
|
+
|
18
|
+
def showing(**dimensions)
|
19
|
+
dup.tap { |it| it.dimensions = clean_dimensions(dimensions || {}) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def select(*metrics)
|
23
|
+
metrics = metrics.flatten.reject(&:nil?) || []
|
24
|
+
raise Flurry::Error, 'at least one metric has to be provided' if metrics.empty?
|
25
|
+
|
26
|
+
dup.tap { |it| it.metrics = metrics }
|
27
|
+
end
|
28
|
+
|
29
|
+
def between(start, finish = nil, format: '%Y-%m-%d')
|
30
|
+
raise Flurry::Error, 'at least start time has to be provided' unless start
|
31
|
+
raise ArgumentError, 'start must be a Time/Date/DateTime' unless datetime?(start)
|
32
|
+
raise ArgumentError, 'finish must be a Time/Date/DateTime' if finish && !datetime?(finish)
|
33
|
+
|
34
|
+
finish = (finish || tomorrow(start)).strftime(format)
|
35
|
+
start = start.strftime(format)
|
36
|
+
|
37
|
+
dup.tap { |it| it.range = [start, finish] }
|
38
|
+
end
|
39
|
+
|
40
|
+
def fetch
|
41
|
+
self.class.get(full_path).response
|
42
|
+
end
|
43
|
+
|
44
|
+
protected
|
45
|
+
|
46
|
+
attr_writer :table, :grain, :dimensions, :metrics, :range
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def clean_dimensions(**dimens)
|
51
|
+
dimens.each_with_object({}) do |(key, val), h|
|
52
|
+
new_value = [val] unless val.is_a? Array
|
53
|
+
new_value ||= val
|
54
|
+
new_value.map! { |v| camelize(v.to_s) unless v.nil? }
|
55
|
+
h[camelize(key.to_s)] = new_value
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def base_partial_path
|
60
|
+
"/#{camelize(@table.to_s)}/#{@grain}"
|
61
|
+
end
|
62
|
+
|
63
|
+
def dimensions_partial_path
|
64
|
+
partial = ''.tap do |path|
|
65
|
+
@dimensions.each do |dimension, fields|
|
66
|
+
path << "/#{dimension}"
|
67
|
+
path << ";show=#{fields.join(',')}" if fields.any?
|
68
|
+
end
|
69
|
+
end if @dimensions
|
70
|
+
|
71
|
+
partial || ''
|
72
|
+
end
|
73
|
+
|
74
|
+
def metrics_partial_path
|
75
|
+
'&metrics=' + @metrics.map do |metric|
|
76
|
+
camelize(metric.to_s) unless metric.nil?
|
77
|
+
end.join(',')
|
78
|
+
end
|
79
|
+
|
80
|
+
def time_range_partial_path
|
81
|
+
"&dateTime=#{@range.join('/')}"
|
82
|
+
end
|
83
|
+
|
84
|
+
def full_path
|
85
|
+
''.tap do |path|
|
86
|
+
path << base_partial_path
|
87
|
+
path << dimensions_partial_path
|
88
|
+
path << '?'
|
89
|
+
path << 'token=' + Flurry.configuration.token
|
90
|
+
path << '&timeZone=' + Flurry.configuration.time_zone if Flurry.configuration.time_zone
|
91
|
+
path << metrics_partial_path
|
92
|
+
path << time_range_partial_path
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/lib/flurry.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'flurry/version'
|
2
|
+
require 'flurry/configuration'
|
3
|
+
require 'flurry/request'
|
4
|
+
|
5
|
+
module Flurry
|
6
|
+
class Error < StandardError; end
|
7
|
+
|
8
|
+
class << self
|
9
|
+
# Start a Flurry configuration block in an initializer.
|
10
|
+
#
|
11
|
+
# Used to provide the Flurry API access token
|
12
|
+
def configure
|
13
|
+
yield configuration
|
14
|
+
end
|
15
|
+
|
16
|
+
def configuration
|
17
|
+
@configuration ||= Configuration.new
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.from(table, group_by = nil)
|
22
|
+
raise Flurry::Error, 'a valid token must be provided before any call' if configuration.token.nil?
|
23
|
+
Request.new(table, group_by)
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flurry
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Roger Bagué
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-02-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.13.7
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.13.7
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: |2
|
70
|
+
Flurry provides easy access to Flurry Analytics Reporting API
|
71
|
+
with a friendly API.
|
72
|
+
email:
|
73
|
+
- rogerbague@gmail.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- LICENSE
|
79
|
+
- lib/flurry.rb
|
80
|
+
- lib/flurry/configuration.rb
|
81
|
+
- lib/flurry/helper.rb
|
82
|
+
- lib/flurry/request.rb
|
83
|
+
- lib/flurry/version.rb
|
84
|
+
homepage: https://github.com/rbague/flurry
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.0.0
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.7.8
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: A wrapper around Flurry Analytics Reporting API
|
108
|
+
test_files: []
|