callback-ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 90d9050e1b2f3fea4e06cf1cdb494be412246c93
4
+ data.tar.gz: 8fa6cace2c221ca716d858e6a60a0713d7a62709
5
+ SHA512:
6
+ metadata.gz: 832576ccaeef14a14e6a327638cf96c7a1389a9dae4cc1a5339913d2c281a47fa1aed36121f40adcc0244d2c4d691ecff636f403fc244688c052a8b867e221c9
7
+ data.tar.gz: 7d4e2dc01a27266392c9d5b565c60e929c4741a781a375fe24823a4b12024e23a09cae36b57c7577bb3be60248add4fb84806c1a9a2a6012cca9ae5de3c12140
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at jamie@brilliantfantastic.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ callback-ruby (0.0.1)
5
+ hashie
6
+ httparty
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.5.1)
12
+ public_suffix (~> 2.0, >= 2.0.2)
13
+ crack (0.4.3)
14
+ safe_yaml (~> 1.0.0)
15
+ diff-lcs (1.3)
16
+ hashdiff (0.3.2)
17
+ hashie (3.4.6)
18
+ httparty (0.14.0)
19
+ multi_xml (>= 0.5.2)
20
+ multi_xml (0.6.0)
21
+ public_suffix (2.0.5)
22
+ rake (12.0.0)
23
+ rspec (3.5.0)
24
+ rspec-core (~> 3.5.0)
25
+ rspec-expectations (~> 3.5.0)
26
+ rspec-mocks (~> 3.5.0)
27
+ rspec-core (3.5.4)
28
+ rspec-support (~> 3.5.0)
29
+ rspec-expectations (3.5.0)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.5.0)
32
+ rspec-mocks (3.5.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.5.0)
35
+ rspec-support (3.5.0)
36
+ safe_yaml (1.0.4)
37
+ webmock (2.3.2)
38
+ addressable (>= 2.3.6)
39
+ crack (>= 0.3.2)
40
+ hashdiff
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ bundler
47
+ callback-ruby!
48
+ rake
49
+ rspec (~> 3.5.0)
50
+ webmock
51
+
52
+ BUNDLED WITH
53
+ 1.14.6
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Tatsu, Inc.
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,91 @@
1
+ Callback.run Ruby API Wrapper
2
+ =============================
3
+
4
+ [ ![Codeship Status for callbackrun/callback-ruby](https://app.codeship.com/projects/2c3b5c50-fd0e-0134-c7bc-22bf4c6edae4/status?branch=master)](https://app.codeship.com/projects/211937)
5
+
6
+ Ruby bindings for the Callback.run API (http://developers.callback.run)
7
+
8
+ ## DESCRIPTION
9
+
10
+ Building scheduling systems takes precious cycles away from concentrating on the building business value. In addition, hosting costs increase to support running background jobs. Callback.run allows you to create recurring jobs that get scheduled and run on Callback's platform. When run, Callback will call a webhook on your servers.
11
+
12
+ This is a Ruby wrapper around the Callback.run API to easily integrate Callback in your Ruby applications.
13
+
14
+ ## INSTALLATION
15
+
16
+ ```
17
+ gem install callback
18
+ ```
19
+
20
+ Using [Bunder](http://bundler.io/), add the following to your `Gemfile`:
21
+
22
+ ```
23
+ gem "callback"
24
+ ```
25
+
26
+ ## BASIC USAGE
27
+
28
+ ### Configure the Client
29
+
30
+ You can configure Callback to use the API key for your team. If you are using Rails, you will want to create an initializer at `config/initializers/callback.rb`
31
+
32
+ ```ruby
33
+ Callback.configure do |config|
34
+ config.access_token = ENV["CALLBACK_ACCESS_TOKEN"]
35
+ end
36
+ ```
37
+
38
+ The following options are available for configuration:
39
+
40
+ | Attribute | Default |
41
+ |----------------|----------------------------|
42
+ | `access_token` | `nil` |
43
+ | `base_path` | `https://api.callback.run` |
44
+
45
+ ### Creating a Client
46
+
47
+ There are several endpoints that hang off of the client. The first thing you want to do is create a client.
48
+
49
+ ```
50
+ client = Callback::Client.new(access_token: "my_token")
51
+ ```
52
+
53
+ If you leave the `access_token` option blank, it will use the access token specified when [configuring the client](#configure-the-client).
54
+
55
+ ### Jobs
56
+
57
+ If you want to perform any CRUD operations on a job, you can use the `jobs` method off of the `Client`.
58
+
59
+ #### Creating a job
60
+
61
+ ```
62
+ job = client.jobs.create(callback_url: "https://example.com/hooks/users/324/welcome",
63
+ payload: { account_id: 1234 })
64
+ ```
65
+
66
+ #### Finding a job
67
+
68
+ ```
69
+ job = client.jobs.find("https://example.com/hooks/users/324/welcome")
70
+ ```
71
+
72
+ ## CONTRIBUTING
73
+
74
+ 1. Clone the repository `git clone https://github.com/callbackrun/callback-ruby`
75
+ 1. Create a feature branch `git checkout -b my-awesome-feature`
76
+ 1. Codez!
77
+ 1. Commit your changes (small commits please)
78
+ 1. Push your new branch `git push origin my-awesome-feature`
79
+ 1. Create a pull request `hub pull-request -b callbackrun:master -h callbackrun:my-awesome-feature`
80
+
81
+ Everyone interacting in Callback's codebases, issue trackers, chat rooms, and mailing lists is expected to follow the Callback [code of conduct](CODE_OF_CONDUCT.md).
82
+
83
+ ## RELEASING A NEW GEM
84
+
85
+ 1. Bump the VERSION in `lib/callback/version.rb`
86
+ 1. Commit changes and push to GitHub
87
+ 1. run `bundle exec rake release`
88
+
89
+ ## LICENSE
90
+
91
+ This project is licensed under the [MIT License](LICENSE.md).
@@ -0,0 +1,16 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :environment do
7
+ ENV["RACK_ENV"] ||= "development"
8
+ require "./lib/callback"
9
+ end
10
+
11
+ desc "Loads the appropriate libraries and then fires up irb"
12
+ task :console => :environment do
13
+ exec "irb -r ./lib/callback.rb"
14
+ end
15
+
16
+ task default: :spec
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require "callback/version"
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = "callback-ruby"
10
+ spec.version = Callback::VERSION
11
+ spec.authors = ["Jamie Wright"]
12
+ spec.email = ["jamie@callback.run"]
13
+
14
+ spec.summary = "A Ruby wrapper for the Callback API"
15
+ spec.description = %q{Callback (http://callback.run) allows you to create a job that runs on a schedule and you get a webhook notification when the job should run. Stop building scheduling systems.}
16
+ spec.homepage = "https://github.com/callbackrun/callback-ruby"
17
+ spec.license = "MIT"
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "hashie"
25
+ spec.add_dependency "httparty"
26
+
27
+ spec.add_development_dependency "bundler"
28
+ spec.add_development_dependency "rake"
29
+ spec.add_development_dependency "rspec", "~> 3.5.0"
30
+ spec.add_development_dependency "webmock"
31
+ end
@@ -0,0 +1,15 @@
1
+ require "callback/api"
2
+ require "callback/client"
3
+ require "callback/configuration"
4
+ require "callback/parser"
5
+ require "callback/version"
6
+
7
+ module Callback
8
+ def self.configuration
9
+ @configuration ||= Configuration.new
10
+ end
11
+
12
+ def self.configure
13
+ yield configuration if block_given?
14
+ end
15
+ end
@@ -0,0 +1,2 @@
1
+ require_relative "api/base"
2
+ require_relative "api/jobs"
@@ -0,0 +1,40 @@
1
+ require "httparty"
2
+ require "callback/parser"
3
+
4
+ module Callback
5
+ module API
6
+ class Base
7
+ include Parser
8
+
9
+ attr_accessor :access_token, :base_path
10
+
11
+ def initialize(access_token: nil, base_path: nil)
12
+ @access_token = access_token
13
+ @base_path = base_path
14
+ end
15
+
16
+ protected
17
+
18
+ def request(method, path, parameters={})
19
+ full_path = "#{base_path}#{path}"
20
+
21
+ options = {
22
+ headers: {
23
+ "Accept" => "application/json",
24
+ "Authorization" => "Bearer #{access_token}",
25
+ "Content-Type" => "application/json; charset=utf-8"
26
+ },
27
+ format: :json
28
+ }
29
+ if method.to_sym == :post
30
+ options[:body] = parameters.to_json
31
+ else
32
+ options[:query] = parameters
33
+ end
34
+
35
+ response = HTTParty.send method, full_path, options
36
+ JSON.parse(response.body, symbolize_names: true)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,16 @@
1
+ module Callback
2
+ module API
3
+ class Jobs < Base
4
+ def create(parameters={})
5
+ parse request(:post, "/jobs", parameters)
6
+ end
7
+
8
+ def find(id_or_callback_url)
9
+ # TODO: This needs to be fixed on the server. It cannot parse periods
10
+
11
+ safe_id = CGI.escape(id_or_callback_url).gsub "\.", "%2E"
12
+ parse request(:get, "/jobs/#{safe_id}")
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ module Callback
2
+ class Client
3
+ attr_accessor :access_token, :base_path
4
+
5
+ def initialize(options={})
6
+ @access_token = initialize_attribute :access_token, options
7
+ @base_path = initialize_attribute :base_path, options
8
+ end
9
+
10
+ def jobs
11
+ @jobs ||= API::Jobs.new(access_token: access_token, base_path: base_path)
12
+ end
13
+
14
+ private
15
+
16
+ def initialize_attribute(key, options)
17
+ options.fetch(key) { Callback.configuration.send(key) }
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,9 @@
1
+ module Callback
2
+ class Configuration
3
+ attr_accessor :access_token, :base_path
4
+
5
+ def initialize
6
+ @base_path = "https://api.callback.run"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require "hashie"
2
+
3
+ module Callback
4
+ module Parser
5
+ def parse(json)
6
+ Hashie::Mash.new json
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Callback
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: callback-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jamie Wright
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-04-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hashie
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: httparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
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
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.5.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.5.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Callback (http://callback.run) allows you to create a job that runs on
98
+ a schedule and you get a webhook notification when the job should run. Stop building
99
+ scheduling systems.
100
+ email:
101
+ - jamie@callback.run
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".rspec"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - LICENSE.md
111
+ - README.md
112
+ - Rakefile
113
+ - callback-ruby.gemspec
114
+ - lib/callback.rb
115
+ - lib/callback/api.rb
116
+ - lib/callback/api/base.rb
117
+ - lib/callback/api/jobs.rb
118
+ - lib/callback/client.rb
119
+ - lib/callback/configuration.rb
120
+ - lib/callback/parser.rb
121
+ - lib/callback/version.rb
122
+ homepage: https://github.com/callbackrun/callback-ruby
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.5.2
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: A Ruby wrapper for the Callback API
146
+ test_files: []