easycron 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 109876a4ac6ec644c3e27890ffd6f86fad4f1fbc
4
+ data.tar.gz: 2cb58d2a6b9452be257bcd1ccf9941304d9ea5bd
5
+ SHA512:
6
+ metadata.gz: 9ed8515a64a9ed366613effee22b8c42f5426c960f5cd8b8ad9fb4f81d53cf1fcc789e11f4af512a7f72aa791b8dbe7e5a259260adb917f9fb4ec837fa46e456
7
+ data.tar.gz: 9b68cb9c407c6cb66c3cb3d906849007ec13d65ad0ddbe8e6a1d065d9691bb8df5dc5ab56d49a663011d6cec4fa6a1aedc4a436dee8362b162b8142bf2097072
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /test.rb
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in easycron.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Genki Sugawara
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.
@@ -0,0 +1,65 @@
1
+ # Easycron
2
+
3
+ [EasyCron](https://www.easycron.com/) API Ruby Client.
4
+
5
+ [![Build Status](https://travis-ci.org/winebarrel/easycron.svg?branch=master)](https://travis-ci.org/winebarrel/easycron)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'easycron'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install easycron
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ require 'uptimerobot'
27
+ require 'pp'
28
+
29
+ client = Easycron::Client.new(token: '...')
30
+
31
+ pp client.list
32
+ #=> {"status"=>"success",
33
+ # "cron_jobs"=>
34
+ # [{"cron_job_id"=>"123456",
35
+ # "cron_job_name"=>"",
36
+ # "user_id"=>"12345",
37
+ # "url"=>"http://example.com",
38
+ # "cron_expression"=>"* * * * *",
39
+ # "number_failed_time"=>"0",
40
+ # "engine_occupied"=>"1",
41
+ # "log_output_length"=>"0",
42
+ # "email_me"=>"0",
43
+ # "status"=>"1",
44
+ # "created"=>"2010-02-03 04:05:06",
45
+ # "updated"=>"2010-02-03 04:05:06"},
46
+ # ...
47
+
48
+ response = client.add(
49
+ cron_expression: '0 0 * * *',
50
+ url: 'http://example.com',
51
+ email_me: 0,
52
+ log_output_length: 0)
53
+
54
+ cron_job_id = response['cron_job_id']
55
+
56
+ response = client.edit(
57
+ cron_expression: '*/5 * * * *',
58
+ url: 'http://www.example.com',
59
+ email_me: 0,
60
+ log_output_length: 0)
61
+ ```
62
+
63
+ ## API Reference
64
+
65
+ - [API Document - EasyCron.com](https://www.easycron.com/document/)
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "easycron"
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
@@ -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,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'easycron/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'easycron'
8
+ spec.version = Easycron::VERSION
9
+ spec.authors = ['Genki Sugawara']
10
+ spec.email = ["sugawara@cookpad.com"]
11
+
12
+ spec.summary = %q{EasyCron API Ruby Client.}
13
+ spec.description = %q{EasyCron API Ruby Client.}
14
+ spec.homepage = 'https://github.com/winebarrel/easycron'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
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 'faraday'
25
+ spec.add_dependency 'faraday_middleware'
26
+
27
+ spec.add_development_dependency 'bundler'
28
+ spec.add_development_dependency 'rake'
29
+ spec.add_development_dependency 'rspec', '~> 3.0'
30
+ end
@@ -0,0 +1,6 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+
4
+ require 'easycron/version'
5
+ require 'easycron/client'
6
+ require 'easycron/error'
@@ -0,0 +1,118 @@
1
+ # see https://www.easycron.com/document
2
+ class Easycron::Client
3
+ ENDPOINT = 'https://www.easycron.com'
4
+ USER_AGENT = "EasyCron API Ruby Cient/#{Easycron::VERSION}"
5
+
6
+ DEFAULT_ADAPTERS = [
7
+ Faraday::Adapter::NetHttp,
8
+ Faraday::Adapter::Test
9
+ ]
10
+
11
+ def initialize(token: , **options)
12
+ raise ArgumentError, ':token is required.' if token.nil?
13
+
14
+ @token = token
15
+ @options = {
16
+ url: ENDPOINT,
17
+ }.merge(options)
18
+
19
+ @conn = Faraday.new(@options) do |faraday|
20
+ faraday.request :url_encoded
21
+ faraday.response :json # content-type: text/html
22
+ faraday.response :raise_error
23
+
24
+ yield(faraday) if block_given?
25
+
26
+ unless DEFAULT_ADAPTERS.any? {|i| faraday.builder.handlers.include?(i) }
27
+ faraday.adapter Faraday.default_adapter
28
+ end
29
+ end
30
+
31
+ @conn.headers[:user_agent] = USER_AGENT
32
+ end
33
+
34
+ def list(page: nil, size: nil, sortby: nil, order: nil)
35
+ request(:list,
36
+ page: page,
37
+ size: size,
38
+ sortby: sortby,
39
+ order: order,
40
+ )
41
+ end
42
+
43
+ def add(cron_job_name: nil, cron_expression:, url: , email_me: , log_output_length: , cookies: nil, posts: nil, via_tor: nil)
44
+ request(:add,
45
+ cron_job_name: cron_job_name,
46
+ cron_expression: cron_expression,
47
+ url: url,
48
+ email_me: email_me,
49
+ log_output_length: log_output_length,
50
+ cookies: cookies,
51
+ posts: posts,
52
+ via_tor: via_tor,
53
+ )
54
+ end
55
+
56
+ def detail(id: )
57
+ request(:detail, id: id)
58
+ end
59
+
60
+ def edit(id: ,cron_job_name: nil, cron_expression:, url: , email_me: , log_output_length: , cookies: nil, posts: nil, via_tor: nil)
61
+ request(:edit,
62
+ id: id,
63
+ cron_job_name: cron_job_name,
64
+ cron_expression: cron_expression,
65
+ url: url,
66
+ email_me: email_me,
67
+ log_output_length: log_output_length,
68
+ cookies: cookies,
69
+ posts: posts,
70
+ via_tor: via_tor,
71
+ )
72
+ end
73
+
74
+ def enable(id: )
75
+ request(:enable, id: id)
76
+ end
77
+
78
+ def disable(id: )
79
+ request(:disable, id: id)
80
+ end
81
+
82
+ def delete(id: )
83
+ request(:delete, id: id)
84
+ end
85
+
86
+ def logs(id: )
87
+ request(:logs, id: id)
88
+ end
89
+
90
+ def timezone
91
+ request(:timezone)
92
+ end
93
+
94
+ private
95
+
96
+ def request(method_name, params = {})
97
+ params = params.merge(token: @token)
98
+ params.reject! {|k, v| v.nil? }
99
+
100
+ response = @conn.get do |req|
101
+ req.url "/rest/#{method_name}"
102
+ req.params = params
103
+ yield(req) if block_given?
104
+ end
105
+
106
+ json = response.body
107
+ validate_response!(json)
108
+ json
109
+ end
110
+
111
+ def validate_response!(json)
112
+ if json.nil?
113
+ raise Easycron::Error
114
+ elsif json['status'] == 'error'
115
+ raise Easycron::Error, json
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,18 @@
1
+ class Easycron::Error < StandardError
2
+ DEFAULT_ERROR_MESSAGE = 'An unexpected error has occurred.'
3
+
4
+ attr_reader :response
5
+ attr_reader :code
6
+
7
+ def initialize(response = nil)
8
+ @response = response
9
+
10
+ if response.nil?
11
+ super DEFAULT_ERROR_MESSAGE
12
+ else
13
+ @code = response.fetch('error', {}).fetch('code', DEFAULT_ERROR_MESSAGE)
14
+ errmsg = response.fetch('error', {}).fetch('message', DEFAULT_ERROR_MESSAGE)
15
+ super errmsg
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module Easycron
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: easycron
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Genki Sugawara
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
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: faraday_middleware
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.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.0'
83
+ description: EasyCron API Ruby Client.
84
+ email:
85
+ - sugawara@cookpad.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - easycron.gemspec
100
+ - lib/easycron.rb
101
+ - lib/easycron/client.rb
102
+ - lib/easycron/error.rb
103
+ - lib/easycron/version.rb
104
+ homepage: https://github.com/winebarrel/easycron
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.5.1
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: EasyCron API Ruby Client.
128
+ test_files: []