logsnag 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/.env.example +1 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +27 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +4 -0
- data/lib/log_snag/client.rb +57 -0
- data/lib/log_snag/log.rb +11 -0
- data/lib/log_snag/version.rb +5 -0
- data/lib/log_snag.rb +11 -0
- data/lib/logsnag.rb +1 -0
- data/logsnag.gemspec +32 -0
- metadata +71 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d88dde87b1c7aca08cfacee42830b74e5557f4650b369636f189ea407bc3f003
|
4
|
+
data.tar.gz: ddac8e808eb01f115a30da170b9dc43ade986ff2c94ea2019afdfc4d0a312a1c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6b72b52ac3b8c6f6b0ee5ccfea80d97225068d91ec987849d73386c97d3963cea662c7c179c0670db03fe2a86ae9c7e9919220871bea4e5db834ac881e892efa
|
7
|
+
data.tar.gz: 958c8d9ceb350f4c581f093f44235de5d7d708d28e27110a7bc049c2ab81e6e36225582c1e676de8fa170db7e607f0b9fc1f1d1157fac054cb9081161b59df56
|
data/.env.example
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
TOKEN=
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
logsnag (0.1.0)
|
5
|
+
faraday (~> 2.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
dotenv (2.7.6)
|
11
|
+
faraday (2.2.0)
|
12
|
+
faraday-net_http (~> 2.0)
|
13
|
+
ruby2_keywords (>= 0.0.4)
|
14
|
+
faraday-net_http (2.0.2)
|
15
|
+
rake (13.0.6)
|
16
|
+
ruby2_keywords (0.0.5)
|
17
|
+
|
18
|
+
PLATFORMS
|
19
|
+
x86_64-linux
|
20
|
+
|
21
|
+
DEPENDENCIES
|
22
|
+
dotenv
|
23
|
+
logsnag!
|
24
|
+
rake (~> 13.0)
|
25
|
+
|
26
|
+
BUNDLED WITH
|
27
|
+
2.3.5
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Dean Perry
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# LogSnag
|
2
|
+
|
3
|
+
Ruby Library for sending LogSnag events.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem "logsnag"
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
### Set Token
|
16
|
+
|
17
|
+
Firstly you'll need to set an API Token.
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
@logsnag = LogSnag::Client.new(token: "")
|
21
|
+
```
|
22
|
+
|
23
|
+
### Sending an Event
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
@logsnag.log(project: "my-project", channel: "channel", event: "my-event")
|
27
|
+
```
|
28
|
+
|
29
|
+
Available Options:
|
30
|
+
|
31
|
+
- description
|
32
|
+
- icon - Single emoji for the event icon
|
33
|
+
- notify - if this event should send a notification
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/deanpcmad/logsnag.
|
38
|
+
|
39
|
+
## License
|
40
|
+
|
41
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
module LogSnag
|
2
|
+
class Client
|
3
|
+
BASE_URL = "https://api.logsnag.com/v1"
|
4
|
+
|
5
|
+
attr_reader :token, :adapter
|
6
|
+
|
7
|
+
def initialize(token:, adapter: Faraday.default_adapter, stubs: nil)
|
8
|
+
@token = token
|
9
|
+
@adapter = adapter
|
10
|
+
|
11
|
+
# Test stubs for requests
|
12
|
+
@stubs = stubs
|
13
|
+
end
|
14
|
+
|
15
|
+
def log(project:, channel:, event:, **params)
|
16
|
+
attributes = {project: project, channel: channel, event: event}
|
17
|
+
Log.new post_request("log", body: attributes.merge(params)).body
|
18
|
+
end
|
19
|
+
|
20
|
+
def connection
|
21
|
+
@connection ||= Faraday.new(BASE_URL) do |conn|
|
22
|
+
conn.request :authorization, :basic, token
|
23
|
+
conn.request :json
|
24
|
+
conn.response :json
|
25
|
+
conn.adapter adapter, @stubs
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def post_request(url, body:, headers: {})
|
32
|
+
handle_response connection.post(url, body, headers)
|
33
|
+
end
|
34
|
+
|
35
|
+
def handle_response(response)
|
36
|
+
case response.status
|
37
|
+
when 400
|
38
|
+
raise Error, "Error 400: Your request was malformed. '#{response.body["message"]}'"
|
39
|
+
when 401
|
40
|
+
raise Error, "Error 401: You did not supply valid authentication credentials. '#{response.body["errors"]}'"
|
41
|
+
when 403
|
42
|
+
raise Error, "Error 403: You are not allowed to perform that action."
|
43
|
+
when 404
|
44
|
+
raise Error, "Error 404: No results were found for your request."
|
45
|
+
when 409
|
46
|
+
raise Error, "Error 409: Your request was a conflict."
|
47
|
+
when 429
|
48
|
+
raise Error, "Error 429: Your request exceeded the API rate limit."
|
49
|
+
when 500
|
50
|
+
raise Error, "Error 500: We were unable to perform the request due to server-side problems."
|
51
|
+
end
|
52
|
+
|
53
|
+
response
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
data/lib/log_snag/log.rb
ADDED
data/lib/log_snag.rb
ADDED
data/lib/logsnag.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "log_snag"
|
data/logsnag.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/log_snag/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "logsnag"
|
7
|
+
spec.version = LogSnag::VERSION
|
8
|
+
spec.authors = ["Dean Perry"]
|
9
|
+
spec.email = ["dean@deanpcmad.com"]
|
10
|
+
|
11
|
+
spec.summary = "Ruby Library for sending LogSnag events"
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = "https://deanpcmad.com"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.6.0"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/deanpcmad/logsnag"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
25
|
+
end
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_dependency "faraday", "~> 2.0"
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logsnag
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dean Perry
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-04-14 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: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
description: Ruby Library for sending LogSnag events
|
28
|
+
email:
|
29
|
+
- dean@deanpcmad.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".env.example"
|
35
|
+
- Gemfile
|
36
|
+
- Gemfile.lock
|
37
|
+
- LICENSE.txt
|
38
|
+
- README.md
|
39
|
+
- Rakefile
|
40
|
+
- lib/log_snag.rb
|
41
|
+
- lib/log_snag/client.rb
|
42
|
+
- lib/log_snag/log.rb
|
43
|
+
- lib/log_snag/version.rb
|
44
|
+
- lib/logsnag.rb
|
45
|
+
- logsnag.gemspec
|
46
|
+
homepage: https://deanpcmad.com
|
47
|
+
licenses:
|
48
|
+
- MIT
|
49
|
+
metadata:
|
50
|
+
homepage_uri: https://deanpcmad.com
|
51
|
+
source_code_uri: https://github.com/deanpcmad/logsnag
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 2.6.0
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubygems_version: 3.2.22
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: Ruby Library for sending LogSnag events
|
71
|
+
test_files: []
|