momentapp 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +5 -0
- data/.rspec +2 -0
- data/Gemfile +20 -0
- data/LICENSE +20 -0
- data/README.md +60 -0
- data/Rakefile +1 -0
- data/lib/core_ext/hash.rb +26 -0
- data/lib/momentapp/version.rb +3 -0
- data/lib/momentapp.rb +87 -0
- data/momentapp.gemspec +20 -0
- data/spec/cassettes_library/.gitkeep +0 -0
- data/spec/momentapp_spec.rb +85 -0
- data/spec/spec_helper.rb +24 -0
- metadata +64 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem 'faraday'
|
4
|
+
gem 'faraday-stack'
|
5
|
+
# gem 'faraday_middleware'
|
6
|
+
gem 'hashie'
|
7
|
+
gem 'activesupport'
|
8
|
+
gem 'i18n'
|
9
|
+
|
10
|
+
group :development do
|
11
|
+
gem 'webmock'
|
12
|
+
gem 'vcr'
|
13
|
+
gem 'fakeweb'
|
14
|
+
gem 'rspec'
|
15
|
+
gem 'ruby-debug', :platforms => :mri_18
|
16
|
+
gem 'ruby-debug19', :require => 'ruby-debug', :platforms => :mri_19
|
17
|
+
end
|
18
|
+
|
19
|
+
# Specify your gem's dependencies in momentapp.gemspec
|
20
|
+
gemspec
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Millisami
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Momentapp
|
2
|
+
|
3
|
+
## Description
|
4
|
+
Momentapp is a ruby wrapper for the [Momentapp][momentapp] service.
|
5
|
+
|
6
|
+
### Installation
|
7
|
+
|
8
|
+
gem install momentapp
|
9
|
+
|
10
|
+
### Usage
|
11
|
+
|
12
|
+
**Configure**
|
13
|
+
|
14
|
+
Momentapp::Config.api_key = [Your api key that you can get from http://momentapp.com]
|
15
|
+
|
16
|
+
**Schedule a new job**
|
17
|
+
|
18
|
+
target_uri = "http://kasko.com"
|
19
|
+
http_method = "GET"
|
20
|
+
at = '2012-01-31T18:36:21'
|
21
|
+
params = {:var1 => true, :var2 => false, :var3 => "ok"}
|
22
|
+
options = {:limit => 3, :callback_uri => "http://callback.com/public/listener"}
|
23
|
+
|
24
|
+
job = Momentapp.create_job(target_uri, http_method, at, params, options)
|
25
|
+
job.id #=> "n9hYHhc1"
|
26
|
+
job.uri #=> "http://kasko.com:80/?var1=true&var2=false&var3=ok"
|
27
|
+
job.http_method #=> "GET"
|
28
|
+
job.at #=> '2012-02-01 08:21:21 +0545'
|
29
|
+
|
30
|
+
**Updating a existing job**
|
31
|
+
|
32
|
+
job_id = job.id
|
33
|
+
target_uri = "http://tesko.com"
|
34
|
+
http_method = "POST"
|
35
|
+
options = {}
|
36
|
+
|
37
|
+
job_update = Momentapp.update_job(job_id, target_uri, http_method, at, params, options)
|
38
|
+
|
39
|
+
**Deleting the job**
|
40
|
+
|
41
|
+
job_id = job.id
|
42
|
+
|
43
|
+
new_result = Momentapp.delete_job(job_id)
|
44
|
+
new_result.message #=> 'Job deleted'
|
45
|
+
|
46
|
+
## Note on Patches/Pull Requests
|
47
|
+
|
48
|
+
* Fork the project.
|
49
|
+
* Make your feature addition or bug fix.
|
50
|
+
* Add tests for it. This is important so I don't break it in a
|
51
|
+
future version unintentionally.
|
52
|
+
* Commit, do not mess with Rakefile, version, or history.
|
53
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
54
|
+
* Send me a pull request. Bonus points for topic branches.
|
55
|
+
|
56
|
+
## Copyright
|
57
|
+
|
58
|
+
Copyright (c) 2011 Millisami. See LICENSE for details.
|
59
|
+
|
60
|
+
[momentapp]: http://momentapp.com
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Opening class Hash to rename_key since the Momentapp api returns a method parameter which is reserved by
|
2
|
+
# Ruby itself. So, to rename method to http_method, we're defining a rename_key method inside Hash class
|
3
|
+
# http://snippets.dzone.com/posts/show/4519
|
4
|
+
class Hash
|
5
|
+
def rename_key(old_key, new_key)
|
6
|
+
return Hash.rename_key(self.dup, old_key, new_key)
|
7
|
+
end
|
8
|
+
|
9
|
+
def rename_key!(old_key, new_key)
|
10
|
+
return Hash.rename_key(self, old_key, new_key)
|
11
|
+
end
|
12
|
+
|
13
|
+
def all_values_empty?
|
14
|
+
self.each_value do |v|
|
15
|
+
return false if v and v != ""
|
16
|
+
end
|
17
|
+
|
18
|
+
return true
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def self.rename_key(hsh, old_key, new_key)
|
23
|
+
hsh[new_key.to_s] = hsh.delete(old_key.to_s)
|
24
|
+
return hsh
|
25
|
+
end
|
26
|
+
end
|
data/lib/momentapp.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'hashie/mash'
|
3
|
+
|
4
|
+
require "momentapp/version"
|
5
|
+
require 'active_support/core_ext'
|
6
|
+
require 'core_ext/hash'
|
7
|
+
|
8
|
+
module Momentapp
|
9
|
+
module Config
|
10
|
+
class << self
|
11
|
+
attr_accessor :api_key
|
12
|
+
|
13
|
+
def configure
|
14
|
+
yield self
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module Connection
|
20
|
+
def connection
|
21
|
+
@connection ||= begin
|
22
|
+
conn = Faraday.new('https://momentapp.com', ssl: {verify: false}) do |b|
|
23
|
+
|
24
|
+
b.request :json
|
25
|
+
b.adapter Faraday.default_adapter
|
26
|
+
end
|
27
|
+
|
28
|
+
conn.headers['User-Agent'] = 'MomentApp Ruby Client'
|
29
|
+
conn
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module ApiMethods
|
35
|
+
def create_job(target_uri, http_method, at, params={}, options={})
|
36
|
+
unless params.nil?
|
37
|
+
target_uri += "?" + params.to_query
|
38
|
+
end
|
39
|
+
|
40
|
+
job_payload = {:method => http_method.upcase, :at => at, :uri => target_uri}
|
41
|
+
|
42
|
+
unless options.nil?
|
43
|
+
valid_option_keys = [:limit, :callback_uri]
|
44
|
+
options.slice(*valid_option_keys)
|
45
|
+
job_payload.merge!({:limit => options[:limit]}) if options[:limit].present?
|
46
|
+
job_payload.merge!({:callback_uri => options[:callback_uri]}) if options[:callback_uri].present?
|
47
|
+
end
|
48
|
+
|
49
|
+
payload = {:job => job_payload}.merge!(:apikey => Momentapp::Config.api_key)
|
50
|
+
response = connection.post '/jobs.json', payload
|
51
|
+
job = Hashie::Mash.new(JSON.load(response.body)['success']['job'])
|
52
|
+
job = job.rename_key!('method', 'http_method')
|
53
|
+
job
|
54
|
+
end
|
55
|
+
|
56
|
+
def update_job(job_id, target_uri, method, at, params={}, options={})
|
57
|
+
unless params.nil?
|
58
|
+
target_uri += "?" + params.to_query
|
59
|
+
end
|
60
|
+
|
61
|
+
job_payload = {:method => method.upcase, :at => at, :uri => target_uri}
|
62
|
+
|
63
|
+
unless options.nil?
|
64
|
+
valid_option_keys = [:limit, :callback_uri]
|
65
|
+
options.slice(*valid_option_keys)
|
66
|
+
job_payload.merge!({:limit => options[:limit]}) if options[:limit].present?
|
67
|
+
job_payload.merge!({:callback_uri => options[:callback_uri]}) if options[:callback_uri].present?
|
68
|
+
end
|
69
|
+
|
70
|
+
payload = {:job => job_payload}.merge!(:apikey => Momentapp::Config.api_key)
|
71
|
+
response = connection.put "/jobs/#{job_id}.json", payload
|
72
|
+
job = Hashie::Mash.new(JSON.load(response.body)['success']['job'])
|
73
|
+
job = job.rename_key!('method', 'http_method')
|
74
|
+
job
|
75
|
+
end
|
76
|
+
|
77
|
+
def delete_job(job_id)
|
78
|
+
response = connection.delete "/jobs/#{job_id}.json?apikey=#{Momentapp::Config.api_key}"
|
79
|
+
job = Hashie::Mash.new(JSON.load(response.body)['success'])
|
80
|
+
job
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
extend Config
|
85
|
+
extend Connection
|
86
|
+
extend ApiMethods
|
87
|
+
end
|
data/momentapp.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "momentapp/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "momentapp"
|
7
|
+
s.version = Momentapp::VERSION
|
8
|
+
s.authors = ["millisami"]
|
9
|
+
s.email = ["millisami@gmail.com"]
|
10
|
+
s.homepage = "http://momentapp.github.com"
|
11
|
+
s.summary = %q{Moment is a ruby wrapper for the Momentapp.com service.}
|
12
|
+
s.description = %q{Moment is a ruby wrapper for the Momentapp.com service. Interaction with the Momentapp API made easy.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "momentapp"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
end
|
File without changes
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Momentapp do
|
4
|
+
context "scheduling a new job" do
|
5
|
+
it "with no parameters" do
|
6
|
+
# WebMock.allow_net_connect!
|
7
|
+
VCR.use_cassette "new_job", :record => :new_episodes do
|
8
|
+
target_uri = "http://kasko.com"
|
9
|
+
method = "GET"
|
10
|
+
at = '2012-01-31T18:36:21'
|
11
|
+
job = Momentapp.create_job(target_uri, method, at)
|
12
|
+
|
13
|
+
job.uri.should eql("http://kasko.com:80/")
|
14
|
+
job.http_method.should eql('GET')
|
15
|
+
job.at.should eql('2012-02-01 08:21:21 +0545')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "with parameters" do
|
20
|
+
# WebMock.allow_net_connect!
|
21
|
+
VCR.use_cassette "new_job_with_params", :record => :new_episodes do
|
22
|
+
target_uri = "http://kasko.com"
|
23
|
+
method = "GET"
|
24
|
+
at = '2012-01-31T18:36:21'
|
25
|
+
params = {:var1 => true, :var2 => false, :var3 => "ok"}
|
26
|
+
job = Momentapp.create_job(target_uri, method, at, params)
|
27
|
+
|
28
|
+
job.uri.should eql("http://kasko.com:80/?var1=true&var2=false&var3=ok")
|
29
|
+
job.http_method.should eql('GET')
|
30
|
+
job.at.should eql('2012-02-01 08:21:21 +0545')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "with parameters and options" do
|
35
|
+
# WebMock.allow_net_connect!
|
36
|
+
VCR.use_cassette "new_job_with_params_n_options", :record => :new_episodes do
|
37
|
+
target_uri = "http://kasko.com"
|
38
|
+
http_method = "GET"
|
39
|
+
at = '2012-01-31T18:36:21'
|
40
|
+
params = {:var1 => true, :var2 => false, :var3 => "ok"}
|
41
|
+
options = {:limit => 3, :callback_uri => "http://callback.com/public/listener"}
|
42
|
+
job = Momentapp.create_job(target_uri, http_method, at, params, options)
|
43
|
+
job.uri.should eql("http://kasko.com:80/?var1=true&var2=false&var3=ok")
|
44
|
+
job.http_method.should eql('GET')
|
45
|
+
job.at.should eql('2012-02-01 08:21:21 +0545')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should update a scheduled job" do
|
51
|
+
# WebMock.allow_net_connect!
|
52
|
+
VCR.use_cassette "update_job", :record => :new_episodes do
|
53
|
+
target_uri = "http://kasko.com"
|
54
|
+
method = "GET"
|
55
|
+
at = '2012-01-31T18:36:21'
|
56
|
+
params = {:var1 => true, :var2 => false, :var3 => "ok"}
|
57
|
+
job = Momentapp.create_job(target_uri, method, at, params)
|
58
|
+
|
59
|
+
job_id = job.id
|
60
|
+
target_uri = "http://tesko.com"
|
61
|
+
method = "POST"
|
62
|
+
options = {}
|
63
|
+
job_update = Momentapp.update_job(job_id, target_uri, method, at, params, options)
|
64
|
+
|
65
|
+
job_update.uri.should eql("http://tesko.com:80/")
|
66
|
+
job_update.http_method.should eql('POST')
|
67
|
+
job_update.at.should eql('2013-02-01 08:21:21 +0545')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should delete a scheduled job" do
|
72
|
+
# WebMock.allow_net_connect!
|
73
|
+
VCR.use_cassette "delete_job", :record => :new_episodes do
|
74
|
+
target_uri = "http://kasko.com"
|
75
|
+
method = "GET"
|
76
|
+
at = '2012-01-31T18:36:21'
|
77
|
+
job = Momentapp.create_job(target_uri, method, at)
|
78
|
+
|
79
|
+
job_id = job.id
|
80
|
+
|
81
|
+
new_result = Momentapp.delete_job(job_id)
|
82
|
+
new_result.message.should eql('Job deleted')
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
|
3
|
+
|
4
|
+
require 'momentapp'
|
5
|
+
require 'vcr'
|
6
|
+
require 'webmock'
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.filter_run :focus => true
|
10
|
+
config.filter_run_excluding :broken => true
|
11
|
+
config.run_all_when_everything_filtered = true
|
12
|
+
config.extend VCR::RSpec::Macros
|
13
|
+
|
14
|
+
config.before(:all) {
|
15
|
+
Momentapp::Config.api_key = "4wV4xjaYbpWRLY_sHYYc"
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
VCR.config do |c|
|
20
|
+
c.cassette_library_dir = 'spec/cassettes_library'
|
21
|
+
c.stub_with :webmock
|
22
|
+
c.ignore_localhost = true
|
23
|
+
c.default_cassette_options = { :record => :none }
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: momentapp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- millisami
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-07-18 00:00:00.000000000 +05:45
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
description: Moment is a ruby wrapper for the Momentapp.com service. Interaction with
|
16
|
+
the Momentapp API made easy.
|
17
|
+
email:
|
18
|
+
- millisami@gmail.com
|
19
|
+
executables: []
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- .gitignore
|
24
|
+
- .rspec
|
25
|
+
- Gemfile
|
26
|
+
- LICENSE
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- lib/core_ext/hash.rb
|
30
|
+
- lib/momentapp.rb
|
31
|
+
- lib/momentapp/version.rb
|
32
|
+
- momentapp.gemspec
|
33
|
+
- spec/cassettes_library/.gitkeep
|
34
|
+
- spec/momentapp_spec.rb
|
35
|
+
- spec/spec_helper.rb
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: http://momentapp.github.com
|
38
|
+
licenses: []
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project: momentapp
|
57
|
+
rubygems_version: 1.6.2
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: Moment is a ruby wrapper for the Momentapp.com service.
|
61
|
+
test_files:
|
62
|
+
- spec/cassettes_library/.gitkeep
|
63
|
+
- spec/momentapp_spec.rb
|
64
|
+
- spec/spec_helper.rb
|