plausible_api 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/README.md +28 -0
- data/lib/plausible_api.rb +13 -0
- data/lib/plausible_api/api/client.rb +32 -0
- data/lib/plausible_api/api/realtime/visitors.rb +11 -0
- data/lib/plausible_api/api/stats/aggregate.rb +19 -0
- data/lib/plausible_api/api/stats/timeseries.rb +11 -0
- data/lib/plausible_api/request.rb +5 -0
- data/lib/plausible_api/version.rb +3 -0
- data/plausible_api.gemspec +21 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b58fa3210ca9873840e437b5a892002428841db0f3f5783ebe17d908e21c4796
|
4
|
+
data.tar.gz: a08c015aaae05008413710e4cc7d367f15fa37385ef5db4d751d072c56255637
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c794f02c31e7bedfd56b461bfc0a66ec8a106583fd71eca4ce2a8c71abce521d69088b93a73b012f8ad6201211b02462778b76d6c876d1084431214d6da1afdd
|
7
|
+
data.tar.gz: 27efd9f3d37cd91c2952800690b5bc5a998f38fc7ef4c40652f56b6c6d843468ef016896f8af945e0a2b11c33d8ed789e8f0f7b99a65a6fff52a8fda7d19a919
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Plausible API (Work In Progress)
|
2
|
+
This is a simple wrapper to read the Plausible API with Ruby.
|
3
|
+
It's based on the WIP [API guide](https://plausible.io/docs/stats-api)
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
Add this gem to your Gemfile:
|
7
|
+
```
|
8
|
+
gem 'plausible_api'
|
9
|
+
```
|
10
|
+
Then you need to initialize a Client and then call one of the available stats:
|
11
|
+
```
|
12
|
+
c = PlausibleApi::Client.new(site_id: 'dailytics.com', token: '123123')
|
13
|
+
c.aggregate(period: '1w', metrics: 'visitors,pageviews,bounce_rate,visit_duration')
|
14
|
+
```
|
15
|
+
|
16
|
+
## Development
|
17
|
+
```
|
18
|
+
$ gem build plausible_api.gemspec
|
19
|
+
$ gem install ./plausible_api-X.X.X.gem
|
20
|
+
$ irb
|
21
|
+
irb(main) > require 'plausible_api'
|
22
|
+
irb(main) > c = PlausibleApi::Client.new(site_id: 'dailytics.com', token: '123123')
|
23
|
+
irb(main) > c.aggregate(period: '1w', metrics: 'visitors,pageviews,bounce_rate,visit_duration')
|
24
|
+
```
|
25
|
+
|
26
|
+
## Todo
|
27
|
+
- Add support for other endpoints
|
28
|
+
- Tests
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'plausible_api/api/realtime/visitors'
|
4
|
+
require 'plausible_api/api/stats/aggregate'
|
5
|
+
require 'plausible_api/api/stats/timeseries'
|
6
|
+
|
7
|
+
require 'faraday'
|
8
|
+
require 'json'
|
9
|
+
|
10
|
+
module PlausibleApi
|
11
|
+
class Client
|
12
|
+
|
13
|
+
BASE_URL = 'https://plausible.io'
|
14
|
+
|
15
|
+
def initialize(site_id:, token:)
|
16
|
+
@site_id = site_id.to_s
|
17
|
+
@token = token
|
18
|
+
end
|
19
|
+
|
20
|
+
def aggregate(period:, metrics:)
|
21
|
+
call PlausibleApi::Stats::Aggregate.new(period: period, metrics: metrics)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def call(resource)
|
26
|
+
res = Faraday.get("#{BASE_URL}/#{resource.request_url.gsub('$SITE_ID', @site_id)}") do |req|
|
27
|
+
req.headers['Authorization'] = "Bearer #{@token}"
|
28
|
+
end
|
29
|
+
JSON.parse res.body
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'plausible_api/request'
|
4
|
+
|
5
|
+
module PlausibleApi
|
6
|
+
module Stats
|
7
|
+
class Aggregate
|
8
|
+
|
9
|
+
def initialize(period: nil, metrics: nil)
|
10
|
+
@period = period || '3m'
|
11
|
+
@metrics = metrics || 'visitors,pageviews,bounce_rate,visit_duration'
|
12
|
+
end
|
13
|
+
|
14
|
+
def request_url
|
15
|
+
"api/v1/stats/aggregate?site_id=$SITE_ID&period=#{@period}&metrics=#{@metrics}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'plausible_api/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |s|
|
9
|
+
s.name = 'plausible_api'
|
10
|
+
s.version = PlausibleApi::VERSION
|
11
|
+
s.summary = 'A simple Plausible API wrapper for Rails'
|
12
|
+
s.description = 'A very humble wrapper for the new API by Plausible'
|
13
|
+
s.authors = ['Gustavo Garcia']
|
14
|
+
s.email = 'gustavo@dailytics.com'
|
15
|
+
s.homepage = 'https://rubygems.org/gems/plausible_api'
|
16
|
+
s.license = 'MIT'
|
17
|
+
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
|
18
|
+
s.require_paths = ['lib']
|
19
|
+
|
20
|
+
s.add_dependency 'faraday'
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: plausible_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gustavo Garcia
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-02-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: A very humble wrapper for the new API by Plausible
|
28
|
+
email: gustavo@dailytics.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- ".gitignore"
|
34
|
+
- README.md
|
35
|
+
- lib/plausible_api.rb
|
36
|
+
- lib/plausible_api/api/client.rb
|
37
|
+
- lib/plausible_api/api/realtime/visitors.rb
|
38
|
+
- lib/plausible_api/api/stats/aggregate.rb
|
39
|
+
- lib/plausible_api/api/stats/timeseries.rb
|
40
|
+
- lib/plausible_api/request.rb
|
41
|
+
- lib/plausible_api/version.rb
|
42
|
+
- plausible_api.gemspec
|
43
|
+
homepage: https://rubygems.org/gems/plausible_api
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubygems_version: 3.1.4
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: A simple Plausible API wrapper for Rails
|
66
|
+
test_files: []
|