plausible_api 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8be1224dad0283128a3e21c2d4e53061845ddc2424e2a89655eb4a129925cb4d
4
- data.tar.gz: b665e6e0dea74c2fe9e1f1309a418cbfe2a5f9be55a4ac0f14845ba6a207fc70
3
+ metadata.gz: 3960123efcdafae0607d993403d5d3ed6108952b623e282e08d97abe5d68b337
4
+ data.tar.gz: 7c03a6435a1d62ca54c07969e09141a546014b093b5ac6e1150b33031f0bdbbf
5
5
  SHA512:
6
- metadata.gz: 645bd976b0dc10c743232daa6752bee9bb5d9e29ee96235ac0d6efa541ffa1d3fe8e3518e510701de377dd3621e44a4c9b0c54cb99a7b50ffe8b85879036ce8c
7
- data.tar.gz: 312e92ef37577f2e58e7ffabf72320bc8c9fc431c651779f0ccd2d264d0aa144e08a10ac8a4c71375ceaed5a17d0814b7d36e8d4446cbcc41278d7b775f3d43b
6
+ metadata.gz: 5b6330d478c5affc54605998832e32d38f72659099279f40cb550a84eda0c0593b61efe0af7c7b0ff581e93ed2c191c47518a9eb6d9fee73fb68617372d85f1f
7
+ data.tar.gz: 53a8202c35ce4507e6144ffb3623ef899822b179b11b716ec60a079aefbbb2fea89d0be1c4e31e6b625c8540dfb5a1160d81224d2a06af9b31d848e422743830
data/README.md CHANGED
@@ -20,9 +20,9 @@ You have all these options to get the aggregate stats
20
20
  c.aggregate
21
21
 
22
22
  # Set parameters (period, metrics, filter, date)
23
- c.aggregate({ period: '3d' })
24
- c.aggregate({ period: '3d', metrics: 'visitors,pageviews' })
25
- c.aggregate({ period: '3d', metrics: 'visitors,pageviews', filter: 'event:page==/order/confirmation' })
23
+ c.aggregate({ period: '30d' })
24
+ c.aggregate({ period: '30d', metrics: 'visitors,pageviews' })
25
+ c.aggregate({ period: '30d', metrics: 'visitors,pageviews', filters: 'event:page==/order/confirmation' })
26
26
 
27
27
  # You'll get something like this:
28
28
  => {"bounce_rate"=>{"value"=>81.0}, "pageviews"=>{"value"=>29}, "visit_duration"=>{"value"=>247.0}, "visitors"=>{"value"=>14}}
@@ -36,11 +36,11 @@ You have all these options to get the timeseries
36
36
  c.timeseries
37
37
 
38
38
  # Set parameters (period, metrics, filter, date)
39
- c.timeseries({ period: '3d' })
40
- c.timeseries({ period: '3d', filter: 'event:page==/order/confirmation', date: '2020/02/10' })
39
+ c.timeseries({ period: '7d' })
40
+ c.timeseries({ period: '7d', filters: 'event:page==/order/confirmation', date: '2020/02/10' })
41
41
 
42
42
  # You'll get something like this:
43
- => [{"date"=>"2021-01-11", "value"=>100}, {"date"=>"2021-01-12", "value"=>120}, {"date"=>"2021-01-13", "value"=>80}]
43
+ => [{"date"=>"2021-01-11", "value"=>100}, {"date"=>"2021-01-12", "value"=>120}, {"date"=>"2021-01-13", "value"=>80}...]
44
44
  ```
45
45
 
46
46
  ### Realtime >> Visitors
@@ -56,9 +56,8 @@ $ gem build plausible_api.gemspec
56
56
  $ gem install ./plausible_api-X.X.X.gem
57
57
  $ irb
58
58
  irb(main) > require 'plausible_api'
59
- irb(main) > c = PlausibleApi::Client.new(site_id: 'dailytics.com', token: '123123')
60
- irb(main) > c.aggregate(period: '1w', metrics: 'visitors,pageviews,bounce_rate,visit_duration')
61
59
  ```
62
60
 
63
61
  ## Todo
64
- - Tests
62
+ - Tests
63
+ - Options validation
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'plausible_api/api/realtime/visitors'
3
+ require 'plausible_api/api/stats/realtime/visitors'
4
4
  require 'plausible_api/api/stats/aggregate'
5
5
  require 'plausible_api/api/stats/timeseries'
6
6
 
@@ -26,7 +26,7 @@ module PlausibleApi
26
26
  end
27
27
 
28
28
  def realtime_visitors
29
- call PlausibleApi::Realtime::Visitors.new
29
+ call PlausibleApi::Stats::Realtime::Visitors.new
30
30
  end
31
31
 
32
32
  private
@@ -4,16 +4,22 @@ module PlausibleApi
4
4
  module Stats
5
5
  class Aggregate
6
6
  def initialize(options = {})
7
- @period = options[:period] || '3mo'
7
+ @period = options[:period] || '30d'
8
8
  @metrics = options[:metrics] || 'visitors,pageviews,bounce_rate,visit_duration'
9
- @filter = options[:filter]
9
+ @filters = options[:filters]
10
10
  @date = options[:date]
11
11
  end
12
12
 
13
13
  def request_url
14
- url = "/api/v1/stats/aggregate?site_id=$SITE_ID&period=#{@period}&metrics=#{@metrics}"
15
- if @filter
16
- url += "&filter=#{CGI.escape(@filter)}"
14
+ url = "/api/v1/stats/aggregate?site_id=$SITE_ID"
15
+ if @period
16
+ url += "&period=#{@period}"
17
+ end
18
+ if @metrics
19
+ url += "&metrics=#{@metrics}"
20
+ end
21
+ if @filters
22
+ url += "&filters=#{CGI.escape(@filters)}"
17
23
  end
18
24
  if @date
19
25
  url += "&date=#{@date}"
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PlausibleApi
4
+ module Stats
5
+ module Realtime
6
+ class Visitors
7
+ def initialize
8
+ end
9
+
10
+ def request_url
11
+ "/api/v1/stats/realtime/visitors?site_id=$SITE_ID"
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -4,15 +4,18 @@ module PlausibleApi
4
4
  module Stats
5
5
  class Timeseries
6
6
  def initialize(options = {})
7
- @period = options[:period] || '3mo'
8
- @filter = options[:filter]
7
+ @period = options[:period] || '30d'
8
+ @filters = options[:filters]
9
9
  @date = options[:date]
10
10
  end
11
11
 
12
12
  def request_url
13
- url = "/api/v1/stats/timeseries?site_id=$SITE_ID&period=#{@period}"
14
- if @filter
15
- url += "&filter=#{CGI.escape(@filter)}"
13
+ url = "/api/v1/stats/timeseries?site_id=$SITE_ID"
14
+ if @period
15
+ url += "&period=#{@period}"
16
+ end
17
+ if @filters
18
+ url += "&filters=#{CGI.escape(@filters)}"
16
19
  end
17
20
  if @date
18
21
  url += "&date=#{@date}"
@@ -1,3 +1,3 @@
1
1
  module PlausibleApi
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plausible_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gustavo Garcia
@@ -34,8 +34,8 @@ files:
34
34
  - README.md
35
35
  - lib/plausible_api.rb
36
36
  - lib/plausible_api/api/client.rb
37
- - lib/plausible_api/api/realtime/visitors.rb
38
37
  - lib/plausible_api/api/stats/aggregate.rb
38
+ - lib/plausible_api/api/stats/realtime/visitors.rb
39
39
  - lib/plausible_api/api/stats/timeseries.rb
40
40
  - lib/plausible_api/version.rb
41
41
  - plausible_api.gemspec
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module PlausibleApi
4
- module Realtime
5
- class Visitors
6
- def initialize
7
- end
8
-
9
- def request_url
10
- "/api/v1/realtime/visitors?site_id=$SITE_ID"
11
- end
12
- end
13
- end
14
- end