ketra 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: 37720a5e1d8c838fe7032637baf15b4a1d2f6dca
4
+ data.tar.gz: 584b3a99ba32c4bd5cf2c1ab2a3342acb3322c78
5
+ SHA512:
6
+ metadata.gz: 52dd7bc1e83bf51bdc8946c56bddbb0da3e1e99c7f217ec0b769b0d2b8b8b1ca7919623c1d767f66f985cc4d608089f521f4791c67693b54aa86aad28b6f105a
7
+ data.tar.gz: 708f84945cbc504c80592aa1226b1d6b3d188963aa1a56c5aae5f16902329c89707c0d9e6546d14edf800fb56d32af31b1acefc308456a33b5b9995d51d04187
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ketra.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 TODO: Write your name
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,56 @@
1
+ # Ketra
2
+
3
+ ## Description
4
+
5
+ The Ketra gem provides a friendly Ruby interface to the Ketra API
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ketra'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ketra
22
+
23
+ ## Usage
24
+
25
+ In order to use this gem you will need to contact Ketra Support and get assigned a client_id and client_secret
26
+
27
+ ### Authentication
28
+
29
+ #### Password grant
30
+
31
+ ```ruby
32
+ require 'ketra'
33
+ Ketra.client_id = 'YOUR CLIENT ID'
34
+ Ketra.client_secret = 'YOUR CLIENT SECRET'
35
+ Ketra.authorization_grant = :password
36
+ credentials = { username: 'YOUR DESIGN STUDIO USERNAME', password: 'YOUR DESIGN STUDIO PASSWORD' }
37
+ Ketra.authorize(credentials)
38
+ access_token = Ketra.access_token
39
+ ```
40
+
41
+
42
+ ## Development
43
+
44
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
45
+
46
+ 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).
47
+
48
+ ## Contributing
49
+
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kennyjpowers/ketra. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
51
+
52
+
53
+ ## License
54
+
55
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
56
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ketra"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/ketra.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ketra/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ketra"
8
+ spec.version = Ketra::VERSION
9
+ spec.authors = ["Kenneth Priester"]
10
+ spec.email = ["kennethjpriester@gmail.com"]
11
+
12
+ spec.summary = %q{Provides a friendly ruby-like wrapper for the Ketra API}
13
+ spec.description = %q{A friendly Ruby interface to the Ketra API}
14
+ spec.homepage = "http://github.com/kennyjpowers/ketra"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "oauth2", "~> 1.3.1"
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.10"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec"
35
+ end
data/lib/ketra.rb ADDED
@@ -0,0 +1,111 @@
1
+ require 'oauth2'
2
+
3
+ require "ketra/version"
4
+ require "ketra/ketra_client"
5
+
6
+ module Ketra
7
+ class Error < RuntimeError; end
8
+
9
+ class << self
10
+ attr_writer :callback_url
11
+ #TODO add permission_scopes
12
+ end
13
+
14
+ # Make Ketra.client_id and Ketra.client_secret global but also local to threads
15
+
16
+ def self.client_id
17
+ Thread.current[:ketra_client_id] || @client_id
18
+ end
19
+
20
+ def self.client_id=(id)
21
+ @client_id ||= id
22
+ Thread.current[:ketra_client_id] = id
23
+ end
24
+
25
+ def self.client_secret
26
+ Thread.current[:client_secret] || @client_secret
27
+ end
28
+
29
+ def self.client_secret=(secret)
30
+ @client_secret ||= secret
31
+ Thread.current[:ketra_client_secret] = secret
32
+ end
33
+
34
+ PRODUCTION_HOST = 'https://my.goketra.com'
35
+ API_VERSION = 'v4'
36
+
37
+ # Set the environment, accepts :production (TODO add :sandbox environment).
38
+ # Defaults to :production
39
+ # will raise an exception when set to an unrecognized environment
40
+ def self.environment=(env)
41
+ unless [:production].include?(env)
42
+ raise(ArguementError, "environment must be set to :production")
43
+ end
44
+ @environment = env
45
+ @host = PRODUCTION_HOST
46
+ end
47
+
48
+ def self.environment
49
+ @environment || :production
50
+ end
51
+
52
+ def self.host
53
+ @host || PRODUCTION_HOST
54
+ end
55
+
56
+ # Set the authorization grant type
57
+ # accepts either :implicit or :password
58
+ # Defaults to :implicit
59
+ def self.authorization_grant=(grant_type)
60
+ unless [:code, :password].include?(grant_type)
61
+ raise(ArgumentError, "grant type must be set to either :code or :password")
62
+ end
63
+ @authorization_grant = grant_type
64
+ end
65
+
66
+ def self.authorization_grant
67
+ @authorization_grant || :code
68
+ end
69
+
70
+ # Allow throwing API errors
71
+ def self.silent_errors=(bool)
72
+ unless [TrueClass, FalseClass].include?(bool.class)
73
+ raise(ArguementError, "Silent errors must be set to either true or false")
74
+ end
75
+ @silent_errors = bool
76
+ end
77
+
78
+ def self.silenet_errors
79
+ @silent_errors.nil? ? false : @silent_errors
80
+ end
81
+
82
+ def self.callback_url
83
+ @callback_url || 'urn:ietf:wg:oauth:2.0:oob'
84
+ end
85
+
86
+ def self.authorization_url
87
+ client.authorization_url
88
+ end
89
+
90
+ # Request Access Token
91
+ # credentials should be key/values based on grant type
92
+ # grant :code should include :authorization_code
93
+ # grant :password should include :username and :password
94
+ def self.authorize(credentials)
95
+ client.authorize(credentials)
96
+ end
97
+
98
+ def self.access_token
99
+ client.access_token.token
100
+ end
101
+
102
+ private
103
+
104
+ def self.client
105
+ @client ||= KetraClient.new
106
+ end
107
+
108
+
109
+
110
+
111
+ end
@@ -0,0 +1,33 @@
1
+ module Ketra
2
+ class KetraClient
3
+
4
+ attr_accessor :access_token
5
+
6
+ # Authorization
7
+
8
+ def authorization_url
9
+ unless Ketra.authorization_grant == :code
10
+ raise(NotImplementedError, "authorization url is only for grant type :code")
11
+ end
12
+ client.auth_code.authorize_url(:redirect_uri => Ketra.callback_url)
13
+ end
14
+
15
+ def authorize(credentials)
16
+ case Ketra.authorization_grant
17
+ when :code
18
+ @access_token ||= client.auth_code.get_token(credentials[:authorization_code], :redirect_uri => Ketra.callback_url)
19
+ when :password
20
+ @access_token ||= client.password.get_token(credentials[:username], credentials[:password])
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def client
27
+ @client ||= OAuth2::Client.new(Ketra.client_id,
28
+ Ketra.client_secret,
29
+ :site => Ketra.host)
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,24 @@
1
+ module Ketra
2
+ class KetraClient
3
+
4
+
5
+
6
+
7
+ # Authorization
8
+
9
+ def authorization_url
10
+ unless authorization_grant == 'implicit'
11
+ raise(NotImplementedError, "authorization url is only for grant type :implicit")
12
+ end
13
+ client.implicit.authorize_url(:redirect_uri => callback_url)
14
+ end
15
+
16
+
17
+ private
18
+
19
+ def client
20
+ @client ||= OAuth2::Client.new(client_id, client_secret, :site => host)
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module Ketra
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ketra
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kenneth Priester
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-05-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: oauth2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.3.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.3.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A friendly Ruby interface to the Ketra API
70
+ email:
71
+ - kennethjpriester@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - ketra.gemspec
87
+ - lib/ketra.rb
88
+ - lib/ketra/ketra_client.rb
89
+ - lib/ketra/ketra_client.rb~
90
+ - lib/ketra/version.rb
91
+ homepage: http://github.com/kennyjpowers/ketra
92
+ licenses:
93
+ - MIT
94
+ metadata:
95
+ allowed_push_host: https://rubygems.org
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.4.5
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Provides a friendly ruby-like wrapper for the Ketra API
116
+ test_files: []