odesk-jobnotifier 0.1.0

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: 8bc371caa79adf4454e72b931b5f17d8b9213261
4
+ data.tar.gz: 026cddec4320586221d537bd222aab989934bb91
5
+ SHA512:
6
+ metadata.gz: 675c4e7139e47ac980cf2dc6af03a82f80ddb4c77bf739a558f6d7f7b6bf410da3b5555b624eb707ac993e48008eb806949f0f4376cfa1203453edf521f7dae6
7
+ data.tar.gz: 0500668c3c63065cc2f8cca56ae3301ffe3beb776bea2f947a369f25cae8b11edba180da701fa796c166d6129e0de8038e87ea0aa925e6a933ffb7ae3a6bb5ef
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ .DS_Store
20
+ .idea/
@@ -0,0 +1,12 @@
1
+ account:
2
+ login: odesk_username
3
+ password: odesk_password
4
+ queries:
5
+ - spellcheck: '1'
6
+ highlight: '1'
7
+ sortBy: 's_ctime desk'
8
+ c1[]: 'Web Development'
9
+ c2[]: 'Web Programming'
10
+ amount[]: '100'
11
+ - 'https://www.odesk.com/jobs/?q=ruby&spellcheck=1&highlight=1&sortBy=s_ctime+desc&c1%5B%5D=Web+Development'
12
+ interval: 30
@@ -0,0 +1,5 @@
1
+ Metrics/ClassLength:
2
+ Max: 300
3
+
4
+ Metrics/MethodLength:
5
+ Max: 30
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in odesk-jobnotifier.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Anton Kolomiychuk
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,32 @@
1
+ # odesk-jobnotifier
2
+ [![Code Climate](https://codeclimate.com/github/akolomiychuk/odesk-jobnotifier/badges/gpa.svg)](https://codeclimate.com/github/akolomiychuk/odesk-jobnotifier)
3
+
4
+ This gem allow you to get real-time notifications about new Odesk jobs on your
5
+ Mac.
6
+
7
+ ## Installation
8
+
9
+ $ gem install odesk-jobnotifier
10
+
11
+ ## Usage
12
+
13
+ You just need to create [.odesk-jobnotifier.yml](https://github.com/akolomiychuk/odesk-jobnotifier/blob/master/.odesk-jobnotifier.example.yml)
14
+ config into your home directory.
15
+
16
+ You should specify your Odesk `username` and `password`.
17
+
18
+ `queries` can be in Hash format or just as Odesk provides it in URL.
19
+
20
+ `interval` used for specifying timeout by which odesk-jobnotifier tries getting
21
+ new jobs.
22
+
23
+ Then you can run `$ odesk_jobnotifier` and app will continually looking over new
24
+ jobs and notifying you.
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it ( http://github.com/akolomiychuk/odesk-jobnotifier/fork )
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'odesk_jobnotifier'
3
+
4
+ OdeskJobnotifier::CommandLineTool.new.run
@@ -0,0 +1,87 @@
1
+ # TODO@akolomiychuk: Ability to store specific jobs in file, for later reading.
2
+ require 'odesk_jobfetch'
3
+ require 'terminal-notifier'
4
+ require 'odesk_jobnotifier/command_line_tool'
5
+ require 'odesk_jobnotifier/version'
6
+
7
+ trap 'SIGINT' do
8
+ puts 'Exiting...'
9
+ exit
10
+ end
11
+
12
+ # Fetches, filters and notifies about last jobs.
13
+ class OdeskJobnotifier
14
+ def initialize(params)
15
+ @account = params[:account]
16
+ @queries = params[:queries]
17
+ @interval = params[:interval]
18
+ @ojf = OdeskJobfetch.new
19
+ end
20
+
21
+ def run
22
+ puts 'Authenticating...'
23
+ @ojf.authorize(@account[:login], @account[:password])
24
+ timestamps = last_timestamps
25
+ puts 'Start looking for new jobs...'
26
+
27
+ loop do
28
+ jobs, timestamps = last_jobs(@queries, timestamps)
29
+ jobs.each { |j| notify(j) }
30
+ sleep(@interval)
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def last_jobs(queries, timestamps)
37
+ total_jobs = []
38
+ threads = job_threads(queries)
39
+ threads.each_with_index do |t, index|
40
+ t.join
41
+ jobs = filter_jobs(t[:jobs], timestamps[index])
42
+ total_jobs += jobs
43
+ timestamps[index] = last_job_timestamp(jobs) unless jobs.empty?
44
+ end
45
+ # Filter the same jobs that can be fetched by different queries.
46
+ [total_jobs.uniq { |j| j['id'] }, timestamps]
47
+ end
48
+
49
+ def job_threads(queries)
50
+ queries.each_with_object([]) do |query, memo|
51
+ memo << Thread.new { Thread.current[:jobs] = fetch_last_jobs(query) }
52
+ end
53
+ end
54
+
55
+ def fetch_last_jobs(query)
56
+ @ojf.fetch(query)
57
+ rescue
58
+ puts 'Error getting last jobs. Skipping...'
59
+ []
60
+ end
61
+
62
+ def filter_jobs(jobs, timestamp)
63
+ jobs.select do |j|
64
+ DateTime.parse(j['publish_time']) > timestamp
65
+ end
66
+ end
67
+
68
+ def last_timestamps
69
+ @queries.map do |q|
70
+ jobs = @ojf.fetch(q)
71
+ last_job_timestamp(jobs)
72
+ end
73
+ end
74
+
75
+ def last_job_timestamp(jobs)
76
+ jobs.map { |j| DateTime.parse(j['publish_time']) }.max
77
+ end
78
+
79
+ def notify(job)
80
+ params = {
81
+ title: "$#{job['client']['total_spent']} | #{job['title']}",
82
+ open: job['url']
83
+ }
84
+
85
+ TerminalNotifier.notify(job['snippet'], params)
86
+ end
87
+ end
@@ -0,0 +1,50 @@
1
+ require 'yaml'
2
+
3
+ class OdeskJobnotifier
4
+ # Handles invoking gem with binary.
5
+ class CommandLineTool
6
+ def initialize(config_dir = Dir.home)
7
+ file_path = "#{config_dir}/.odesk-jobnotifier.yml"
8
+ if File.exist?(file_path)
9
+ config = YAML.load_file(file_path)
10
+ config['queries'] = convert_query_string_params(config['queries'])
11
+ @config = convert_params(config)
12
+ else
13
+ abort("Configuration file #{file_path} is missing.")
14
+ end
15
+ end
16
+
17
+ def run
18
+ OdeskJobnotifier.new(@config).run
19
+ end
20
+
21
+ private
22
+
23
+ def convert_query_string_params(queries)
24
+ queries.map do |q|
25
+ if q.instance_of?(String)
26
+ CGI.parse(URI(q).query).each_with_object({}) do |(k, v), memo|
27
+ memo[k] = v.first
28
+ end
29
+ else
30
+ q
31
+ end
32
+ end
33
+ end
34
+
35
+ def convert_params(params)
36
+ params.each_with_object({}) do |(k, v), memo|
37
+ memo[k.to_sym] =
38
+ if v.instance_of?(Hash)
39
+ convert_params(v)
40
+ elsif v.instance_of?(Array)
41
+ memo[k.to_sym] = v.map do |el|
42
+ el.instance_of?(Hash) ? convert_params(el) : el
43
+ end
44
+ else
45
+ memo[k.to_sym] = v
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,4 @@
1
+ #:nodoc:
2
+ class OdeskJobnotifier
3
+ VERSION = '0.1.0'
4
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'odesk_jobnotifier/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'odesk-jobnotifier'
8
+ spec.version = OdeskJobnotifier::VERSION
9
+ spec.authors = ['Anton Kolomiychuk']
10
+ spec.email = ['kolomiychuk.anton+gh@gmail.com']
11
+ spec.summary = 'Get real-time notifications about new jobs on Odesk' \
12
+ ' on your Mac.'
13
+ spec.homepage = 'https://github.com/akolomiychuk/odesk-jobnotifier'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($RS)
17
+ spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(/^(test|spec|features)\//)
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.required_ruby_version = '>= 1.9.0'
22
+
23
+ spec.add_runtime_dependency 'odesk-jobfetch'
24
+ spec.add_runtime_dependency 'terminal-notifier', '~> 1.6'
25
+
26
+ spec.add_development_dependency 'rubocop', '~> 0.25'
27
+ spec.add_development_dependency 'bundler', '~> 1.5'
28
+ spec.add_development_dependency 'rake'
29
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: odesk-jobnotifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Anton Kolomiychuk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: odesk-jobfetch
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: terminal-notifier
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.25'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.25'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - kolomiychuk.anton+gh@gmail.com
86
+ executables:
87
+ - odesk_jobnotifier
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".odesk-jobnotifier.example.yml"
93
+ - ".rubocop.yml"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/odesk_jobnotifier
99
+ - lib/odesk_jobnotifier.rb
100
+ - lib/odesk_jobnotifier/command_line_tool.rb
101
+ - lib/odesk_jobnotifier/version.rb
102
+ - odesk-jobnotifier.gemspec
103
+ homepage: https://github.com/akolomiychuk/odesk-jobnotifier
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: 1.9.0
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.2.1
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Get real-time notifications about new jobs on Odesk on your Mac.
127
+ test_files: []