desklight 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3dd5dec252cd8f9cd9475dbeeda0191a0a9bcb7d
4
+ data.tar.gz: a67ca3aadcde2603b6f96e8892c262a9a39752c5
5
+ SHA512:
6
+ metadata.gz: 4f3c14d67c2666763b9087d497641a0e6f3d86b9189dd9f36b23ef79e079bd934bffea5a7cdc004a68a5be4023fe78b3bfec19cfa8f7cb375d7f35b1a82713e1
7
+ data.tar.gz: d7a57242c41847fc819472a758ec0d5938d15691c6351c701d543ff9b202c2196760742d50d12dab0dbf325d6d925af286980a9d79c2d987ca31e237b7793ec7
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Desklight
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/desklight`. 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 'desklight'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install desklight
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]/desklight. 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 Desklight project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/desklight/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 "desklight"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
1
+ module DeskLight
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}.desk.com")
10
+ end
11
+ attr_accessor :email
12
+ attr_accessor :password
13
+ attr_accessor :key
14
+ attr_accessor :secret
15
+ attr_accessor :api_token
16
+ attr_accessor :api_secret
17
+ def initialize
18
+ self.rpm = 300
19
+ self.api_path = "/api/v2"
20
+ end
21
+ def [](value)
22
+ self.public_send(value)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,66 @@
1
+ require 'desk_light/response'
2
+ require 'open-uri'
3
+ require 'oauth'
4
+
5
+
6
+ module DeskLight
7
+ module Requester
8
+ def self.get *args
9
+ _uri = URI.parse("https://#{DeskLight.config.subdomain}.desk.com" << DeskLight.config.api_path << "/" << args.first.to_s)
10
+ _params = CGI.parse(_uri.query || "")
11
+ _path = DeskLight.config.api_path
12
+ args.shift
13
+ args.each do |arg|
14
+ case arg.class.name
15
+ when 'Symbol','String','Integer'
16
+ _path << "/" << arg.to_s
17
+ when 'Hash'
18
+ _params.merge!(arg)
19
+ end
20
+ end
21
+ _url = "#{_uri.scheme}://#{_uri.host}#{_uri.path}"
22
+ _url << "?#{URI.encode_www_form(_params)}" if _params.count > 0
23
+ consumer = OAuth::Consumer.new(
24
+ DeskLight.config.key,
25
+ DeskLight.config.secret,
26
+ :scheme => :header
27
+ )
28
+ access_token = OAuth::AccessToken.from_hash(
29
+ consumer,
30
+ :oauth_token => DeskLight.config.api_token,
31
+ :oauth_token_secret => DeskLight.config.api_secret
32
+ )
33
+ DeskLight::Response.new(access_token.get(_url))
34
+ end
35
+
36
+
37
+ def self.download _url, _authenticate = true
38
+ uri = URI.parse(_url)
39
+ path = uri.path
40
+ path << "?#{uri.query}" if (uri.query || "").strip != ""
41
+ if _authenticate
42
+ consumer = OAuth::Consumer.new(
43
+ DeskLight.config.key,
44
+ DeskLight.config.secret,
45
+ scheme: :header
46
+ )
47
+ access_token = OAuth::AccessToken.from_hash(
48
+ consumer,
49
+ oauth_token: DeskLight.config.api_token,
50
+ oauth_token_secret: DeskLight.config.api_secret
51
+ )
52
+ response = access_token.get(_url)
53
+ else
54
+ http = Net::HTTP.new(uri.host,uri.port)
55
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
56
+ http.use_ssl = DeskLight.config.uri.scheme == 'https'
57
+ request = Net::HTTP::Get.new(path)
58
+ response = http.request(request)
59
+ end
60
+ if location = response['location']
61
+ return self.download(location,false)
62
+ end
63
+ DeskLight::Response.new(response)
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,44 @@
1
+ require 'json'
2
+
3
+
4
+ module DeskLight
5
+ class Response
6
+ attr_reader :code
7
+ attr_reader :json
8
+ attr_reader :limit
9
+ attr_reader :remaining
10
+ attr_reader :reset
11
+ attr_reader :body
12
+ attr_reader :either
13
+ attr_reader :time
14
+ attr_reader :headers
15
+
16
+ def initialize _response, _time = nil
17
+ @limit = _response['x-rate-limit-limit']
18
+ @limit = @limit.to_i if @limit
19
+ @remaining = _response['x-rate-limit-remaining']
20
+ @remaining = @remaining.to_i if @remaining
21
+ @reset = _response['x-rate-limit-reset']
22
+ @reset = @reset.to_i if @reset
23
+ @code = _response.code.to_i
24
+ if content_type = _response['content-type']
25
+ if content_type.include?("application/json")
26
+ begin
27
+ @json = JSON.parse(_response.body)
28
+ rescue
29
+ @json = nil
30
+ end
31
+ end
32
+ else
33
+ @json = nil
34
+ end
35
+ @body = _response.body
36
+ @either = @json || @body
37
+ @time = (Time.now - _time).to_f if _time
38
+ @headers = {}
39
+ _response.each do |key,val|
40
+ @headers.merge!(key => val)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module DeskLight
2
+ VERSION = "0.1.0"
3
+ end
data/lib/desk_light.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'desk_light/version'
2
+ require 'desk_light/configuration'
3
+ require 'desk_light/requester'
4
+
5
+
6
+ module DeskLight
7
+ def self.configure
8
+ @config ||= DeskLight::Configuration.new
9
+ yield(@config) if block_given?
10
+ @config
11
+ end
12
+ def self.config
13
+ @config || self.configure
14
+ end
15
+ def self.get *args
16
+ DeskLight::Requester.get(*args)
17
+ end
18
+ def self.download _url
19
+ DeskLight::Requester.download(_url)
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: desklight
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - onlyexcellence
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-09-28 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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: awesome_print
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: colorize
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: oauth
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.5'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.5'
97
+ description:
98
+ email:
99
+ - will@wambl.com
100
+ executables:
101
+ - console
102
+ - setup
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - README.md
107
+ - bin/console
108
+ - bin/setup
109
+ - lib/desk_light.rb
110
+ - lib/desk_light/configuration.rb
111
+ - lib/desk_light/requester.rb
112
+ - lib/desk_light/response.rb
113
+ - lib/desk_light/version.rb
114
+ homepage: https://github.com/onlyexcellence/desklight
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.6.13
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: Desk.com API
138
+ test_files: []