pirsch_api 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/pirsch_api/client.rb +17 -16
- data/lib/pirsch_api/error.rb +1 -1
- data/lib/pirsch_api/object.rb +1 -1
- data/lib/pirsch_api/objects/active.rb +1 -1
- data/lib/pirsch_api/objects/domain.rb +1 -1
- data/lib/pirsch_api/objects/duration_page.rb +1 -1
- data/lib/pirsch_api/objects/duration_session.rb +1 -1
- data/lib/pirsch_api/objects/event.rb +1 -1
- data/lib/pirsch_api/objects/growth.rb +1 -1
- data/lib/pirsch_api/objects/page.rb +1 -1
- data/lib/pirsch_api/objects/referrer.rb +1 -1
- data/lib/pirsch_api/objects/token.rb +1 -1
- data/lib/pirsch_api/objects/utm_campaign.rb +1 -1
- data/lib/pirsch_api/objects/utm_medium.rb +1 -1
- data/lib/pirsch_api/objects/utm_source.rb +1 -1
- data/lib/pirsch_api/objects/visitor.rb +1 -1
- data/lib/pirsch_api/resources/base.rb +7 -8
- data/lib/pirsch_api/resources/domain.rb +2 -2
- data/lib/pirsch_api/resources/statistics/active.rb +1 -1
- data/lib/pirsch_api/resources/statistics/duration_page.rb +3 -3
- data/lib/pirsch_api/resources/statistics/duration_session.rb +3 -3
- data/lib/pirsch_api/resources/statistics/event.rb +3 -2
- data/lib/pirsch_api/resources/statistics/growth.rb +1 -1
- data/lib/pirsch_api/resources/statistics/page.rb +2 -2
- data/lib/pirsch_api/resources/statistics/referrer.rb +2 -2
- data/lib/pirsch_api/resources/statistics/utm_campaign.rb +3 -3
- data/lib/pirsch_api/resources/statistics/utm_medium.rb +3 -3
- data/lib/pirsch_api/resources/statistics/utm_source.rb +3 -3
- data/lib/pirsch_api/resources/statistics/visitor.rb +2 -2
- data/lib/pirsch_api/resources/token.rb +7 -9
- data/lib/pirsch_api/version.rb +1 -1
- data/lib/pirsch_api.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 006765cdfc16afa484a20da5b5e7e507dc50a5fe41e7cf6a869199d9d3112241
|
4
|
+
data.tar.gz: adf718d65c7d1f74a0b3f48a2803b778dc15d58c0b2f38e7730dc387e7f076a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec39210e5901821c896b82c6a0f551adbfc541bd007403f7ef91c8147abebc67e75408ce7d691b530226a7a118753c290f0903960e18aaafdab4f7be0ec17285
|
7
|
+
data.tar.gz: fe077953f1d9a7ca5b69a945688e37ae8d0dcffcd158ca4b46e0fca1940a38580bd8686599b322c027adfba5298e2b4b4dcfd4c773a7356927b65c0e27140134
|
data/Gemfile.lock
CHANGED
data/lib/pirsch_api/client.rb
CHANGED
@@ -2,16 +2,17 @@
|
|
2
2
|
|
3
3
|
module PirschApi
|
4
4
|
class Client
|
5
|
-
|
6
|
-
BASE_URL = 'https://api.pirsch.io/api/v1'
|
5
|
+
BASE_URL = "https://api.pirsch.io/api/v1"
|
7
6
|
|
8
7
|
def initialize(client_id:, client_secret:)
|
9
|
-
@client_id
|
8
|
+
@client_id = client_id.to_s
|
10
9
|
@client_secret = client_secret.to_s
|
11
10
|
end
|
12
11
|
|
13
12
|
def valid?
|
14
|
-
true if token
|
13
|
+
true if token
|
14
|
+
rescue
|
15
|
+
false
|
15
16
|
end
|
16
17
|
|
17
18
|
def token
|
@@ -22,48 +23,48 @@ module PirschApi
|
|
22
23
|
DomainResource.new(client: self).run
|
23
24
|
end
|
24
25
|
|
25
|
-
def visitors(filters: {}
|
26
|
+
def visitors(domain:, filters: {})
|
26
27
|
VisitorResource.new(client: self, filters: filters, domain: domain).run
|
27
28
|
end
|
28
29
|
|
29
|
-
def pages(filters: {}
|
30
|
+
def pages(domain:, filters: {})
|
30
31
|
PageResource.new(client: self, filters: filters, domain: domain).run
|
31
32
|
end
|
32
33
|
|
33
|
-
def referrers(filters: {}
|
34
|
+
def referrers(domain:, filters: {})
|
34
35
|
ReferrerResource.new(client: self, filters: filters, domain: domain).run
|
35
36
|
end
|
36
37
|
|
37
|
-
def active(filters: {}
|
38
|
+
def active(domain:, filters: {})
|
38
39
|
ActiveResource.new(client: self, filters: filters, domain: domain).run
|
39
40
|
end
|
40
41
|
|
41
|
-
def growth(filters: {}
|
42
|
+
def growth(domain:, filters: {})
|
42
43
|
GrowthResource.new(client: self, filters: filters, domain: domain).run
|
43
44
|
end
|
44
45
|
|
45
|
-
def events(filters: {}
|
46
|
+
def events(domain:, filters: {})
|
46
47
|
EventResource.new(client: self, filters: filters, domain: domain).run
|
47
48
|
end
|
48
49
|
|
49
|
-
def utm_source(filters: {}
|
50
|
+
def utm_source(domain:, filters: {})
|
50
51
|
UtmSourceResource.new(client: self, filters: filters, domain: domain).run
|
51
52
|
end
|
52
53
|
|
53
|
-
def utm_medium(filters: {}
|
54
|
+
def utm_medium(domain:, filters: {})
|
54
55
|
UtmMediumResource.new(client: self, filters: filters, domain: domain).run
|
55
56
|
end
|
56
57
|
|
57
|
-
def utm_campaign(filters: {}
|
58
|
+
def utm_campaign(domain:, filters: {})
|
58
59
|
UtmCampaignResource.new(client: self, filters: filters, domain: domain).run
|
59
60
|
end
|
60
61
|
|
61
|
-
def duration_session(filters: {}
|
62
|
+
def duration_session(domain:, filters: {})
|
62
63
|
DurationSessionResource.new(client: self, filters: filters, domain: domain).run
|
63
64
|
end
|
64
65
|
|
65
|
-
def duration_page(filters: {}
|
66
|
+
def duration_page(domain:, filters: {})
|
66
67
|
DurationPageResource.new(client: self, filters: filters, domain: domain).run
|
67
68
|
end
|
68
69
|
end
|
69
|
-
end
|
70
|
+
end
|
data/lib/pirsch_api/error.rb
CHANGED
data/lib/pirsch_api/object.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module PirschApi
|
2
2
|
class BaseResource
|
3
|
-
|
4
3
|
attr_accessor :client, :filters, :domain
|
5
4
|
|
6
5
|
def initialize(client:, domain: nil, filters: {})
|
@@ -19,7 +18,7 @@ module PirschApi
|
|
19
18
|
end
|
20
19
|
|
21
20
|
def errors
|
22
|
-
@errors[:client] =
|
21
|
+
@errors[:client] = "client is invalid" unless client.valid?
|
23
22
|
@errors
|
24
23
|
end
|
25
24
|
|
@@ -29,24 +28,24 @@ module PirschApi
|
|
29
28
|
|
30
29
|
def run
|
31
30
|
raise PirschApi::Error.new errors unless valid?
|
32
|
-
|
31
|
+
|
33
32
|
if domain
|
34
33
|
filters[:id] = domain.to_s
|
35
34
|
end
|
36
35
|
|
37
36
|
url = "#{PirschApi::Client::BASE_URL}/#{request_url}"
|
38
|
-
url << "?#{filters.to_a.map { |x| "#{x[0]}=#{x[1]}" }.join("&")
|
37
|
+
url << "?#{filters.to_a.map { |x| "#{x[0]}=#{CGI.escape(x[1])}" }.join("&")}" if filters.any?
|
39
38
|
|
40
39
|
puts "[Pirsch API] run #{url}"
|
41
40
|
|
42
41
|
uri = URI.parse url
|
43
42
|
|
44
43
|
req = Net::HTTP::Get.new(uri.request_uri)
|
45
|
-
req.add_field(
|
44
|
+
req.add_field("Authorization", "Bearer #{client.token.access_token}")
|
46
45
|
|
47
46
|
http = Net::HTTP.new(uri.host, uri.port)
|
48
|
-
http.use_ssl = true
|
49
|
-
|
47
|
+
http.use_ssl = true
|
48
|
+
|
50
49
|
response = http.request(req)
|
51
50
|
raise PirschApi::Error.new "Api request failed (#{response.body})" unless response.code == "200"
|
52
51
|
raise PirschApi::Error.new "Api request returned nil (#{response.body})" if response.body.nil?
|
@@ -54,4 +53,4 @@ module PirschApi
|
|
54
53
|
parse_response response.body
|
55
54
|
end
|
56
55
|
end
|
57
|
-
end
|
56
|
+
end
|
@@ -1,12 +1,10 @@
|
|
1
1
|
module PirschApi
|
2
|
-
|
3
2
|
class TokenResource
|
4
|
-
|
5
3
|
def initialize(client_id, client_secret)
|
6
|
-
@client_id
|
4
|
+
@client_id = client_id
|
7
5
|
@client_secret = client_secret
|
8
6
|
end
|
9
|
-
|
7
|
+
|
10
8
|
def request_url
|
11
9
|
"token"
|
12
10
|
end
|
@@ -29,16 +27,16 @@ module PirschApi
|
|
29
27
|
http = Net::HTTP.new(uri.host, uri.port)
|
30
28
|
http.use_ssl = true
|
31
29
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
32
|
-
|
33
|
-
header = {
|
30
|
+
|
31
|
+
header = {"Content-Type": "text/json"}
|
34
32
|
request = Net::HTTP::Post.new(uri.request_uri, header)
|
35
33
|
request.body = request_body
|
36
|
-
|
34
|
+
|
37
35
|
response = http.request(request)
|
38
36
|
|
39
37
|
raise Error.new "Token request failed. (#{response.body})" unless response.code == "200"
|
40
|
-
|
38
|
+
|
41
39
|
parse_response(response.body)
|
42
40
|
end
|
43
41
|
end
|
44
|
-
end
|
42
|
+
end
|
data/lib/pirsch_api/version.rb
CHANGED
data/lib/pirsch_api.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pirsch_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gustavo Garcia
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A very humble wrapper for the API by Pirsch.io
|
14
14
|
email:
|
@@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
requirements: []
|
84
|
-
rubygems_version: 3.
|
84
|
+
rubygems_version: 3.3.7
|
85
85
|
signing_key:
|
86
86
|
specification_version: 4
|
87
87
|
summary: A simple Pirsch Analytics API wrapper for Rails
|