zenlight 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +43 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/zenlight/configuration.rb +30 -0
- data/lib/zenlight/requester.rb +42 -0
- data/lib/zenlight/response.rb +38 -0
- data/lib/zenlight/version.rb +3 -0
- data/lib/zenlight.rb +22 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 23192ab74b22208aad05c3e5e03b2eca654af1bf
|
4
|
+
data.tar.gz: 78061eedc7a082400f874e5b2d6128a0d1062fab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 764cbad8939f775b2aeb2b971981d622296292c0f9bded91fe67256b653512f07c47b8a0c75329d6e88f019c11b3add770b1f56266b0fe54283cfd98426ba398
|
7
|
+
data.tar.gz: 8e3990acdfdf52f54c06222a4329d543b222b4f9a0cc32293db6af477016c79bc8b3789d6ae1b5393b479427df733b3951ab0bb423b979c2d2ef8090afea6a48
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Zenlight
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/zenlight`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'zenlight'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install zenlight
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/zenlight. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the Zenlight project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/zenlight/blob/master/CODE_OF_CONDUCT.md).
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "zenlight"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Zenlight
|
2
|
+
class Configuration
|
3
|
+
attr_reader :uri
|
4
|
+
attr_accessor :subdomain
|
5
|
+
attr_accessor :rpm
|
6
|
+
attr_accessor :api_path
|
7
|
+
def subdomain=(value)
|
8
|
+
@subdomain = value
|
9
|
+
@uri = URI.parse("https://#{@subdomain}.zendesk.com")
|
10
|
+
end
|
11
|
+
attr_accessor :email
|
12
|
+
attr_accessor :password
|
13
|
+
attr_accessor :token
|
14
|
+
def initialize
|
15
|
+
self.rpm = 700
|
16
|
+
self.api_path = "/api/v2"
|
17
|
+
end
|
18
|
+
def [](value)
|
19
|
+
self.public_send(value)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
def self.configure
|
23
|
+
@config ||= Zenlight::Configuration.new
|
24
|
+
yield(@config) if block_given?
|
25
|
+
@config
|
26
|
+
end
|
27
|
+
def self.config
|
28
|
+
@config || self.configure
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'zenlight/response'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
|
6
|
+
module Zenlight
|
7
|
+
module Requester
|
8
|
+
def get _path, _params = nil
|
9
|
+
setup = {
|
10
|
+
method: __callee__.to_s,
|
11
|
+
url: "https://#{self.config.subdomain}.zendesk.com" << _path,
|
12
|
+
user: "#{self.config.email}/token",
|
13
|
+
password: self.config.token,
|
14
|
+
headers: {
|
15
|
+
accept: :json,
|
16
|
+
content_type: :json
|
17
|
+
}
|
18
|
+
}
|
19
|
+
case __callee__.to_s.downcase
|
20
|
+
when "get","post","put","patch"
|
21
|
+
if setup[:url].include?('upload') || setup[:url].include?('/attachments')
|
22
|
+
setup[:headers][:content_type] = 'application/*'
|
23
|
+
setup[:payload] = _params
|
24
|
+
else
|
25
|
+
setup[:headers][:content_type] = :json
|
26
|
+
setup.merge!(payload: _params.to_json) if _params
|
27
|
+
end
|
28
|
+
setup[:headers][:content_type] = 'application/merge-patch+json' if __callee__.to_s.downcase == "patch"
|
29
|
+
end
|
30
|
+
prepared = RestClient::Request.new(setup)
|
31
|
+
begin
|
32
|
+
response = Zenlight::Response.new(prepared.execute)
|
33
|
+
rescue RestClient::ExceptionWithResponse => e
|
34
|
+
response = Zenlight::Response.new(e.response)
|
35
|
+
end
|
36
|
+
response
|
37
|
+
end
|
38
|
+
def download _url
|
39
|
+
open(_url).read.force_encoding("UTF-8")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
|
4
|
+
module Zenlight
|
5
|
+
class Response
|
6
|
+
attr_reader :code
|
7
|
+
attr_reader :json
|
8
|
+
attr_reader :limit
|
9
|
+
attr_reader :remaining
|
10
|
+
attr_reader :body
|
11
|
+
attr_reader :either
|
12
|
+
attr_reader :time
|
13
|
+
attr_reader :headers
|
14
|
+
|
15
|
+
def initialize _response, _time = nil
|
16
|
+
@limit = _response.headers[:x_rate_limit] || _response.headers[:x_ratelimit_limit_minute] || _response.headers[:x_ratelimit_total]
|
17
|
+
@limit = @limit.to_i if @limit
|
18
|
+
@remaining = _response.headers[:x_rate_limit_remaining] || _response.headers[:x_ratelimit_remaining_minute] || _response.headers[:x_ratelimit_remaining]
|
19
|
+
@remaining = @remaining.to_i if @remaining
|
20
|
+
@code = _response.code.to_i
|
21
|
+
if content_type = _response.headers[:content_type]
|
22
|
+
if content_type.include?("application/json")
|
23
|
+
begin
|
24
|
+
@json = JSON.parse(_response.body)
|
25
|
+
rescue
|
26
|
+
@json = nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
else
|
30
|
+
@json = nil
|
31
|
+
end
|
32
|
+
@body = _response.body
|
33
|
+
@either = @json || @body
|
34
|
+
@time = (Time.now - _time).to_f if _time
|
35
|
+
@headers = _response.headers
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/zenlight.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'zenlight/version'
|
2
|
+
require 'zenlight/configuration'
|
3
|
+
require 'zenlight/requester'
|
4
|
+
|
5
|
+
|
6
|
+
module Zenlight
|
7
|
+
class Instance
|
8
|
+
include Zenlight::Requester
|
9
|
+
alias :post :get
|
10
|
+
alias :put :get
|
11
|
+
alias :patch :get
|
12
|
+
alias :delete :get
|
13
|
+
def initialize
|
14
|
+
@config ||= Zenlight::Configuration.new
|
15
|
+
yield(@config) if block_given?
|
16
|
+
@config
|
17
|
+
end
|
18
|
+
def config
|
19
|
+
@config || self.configure
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zenlight
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- onlyexcellence
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-09-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rest-client
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.1'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- will@wambl.com
|
58
|
+
executables:
|
59
|
+
- console
|
60
|
+
- setup
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- README.md
|
65
|
+
- bin/console
|
66
|
+
- bin/setup
|
67
|
+
- lib/zenlight.rb
|
68
|
+
- lib/zenlight/configuration.rb
|
69
|
+
- lib/zenlight/requester.rb
|
70
|
+
- lib/zenlight/response.rb
|
71
|
+
- lib/zenlight/version.rb
|
72
|
+
homepage: https://github.com/onlyexcellence/zenlight
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.6.13
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Zendesk API
|
96
|
+
test_files: []
|