idonethis-cli 0.2.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: 8624391974fcde339f8bb2037b5a91faf3eb8482
4
+ data.tar.gz: 9642d0a22baf60a1b0b3a7368b45ffa1f326352b
5
+ SHA512:
6
+ metadata.gz: 8c2cd366f355fd61bec701c5815da3e1d683c7cd860de2a1e6c4db32a9dcc556dd0968cb424d4746c8cb8eee732210d74f8c96254d91e6157443740d6e4b9375
7
+ data.tar.gz: 0eae6000907e29ccdd7c19c22ba435040c227330383b11e0586fd00f19f65d5091291c4e875005a80cf1ae995ee0b4fd1c2f8a1d41716bd66ac382aa7862518a
data/.gitignore ADDED
@@ -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
+ .settings
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Ben Biddington
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,50 @@
1
+ A CLI for idonethis.
2
+
3
+ ## Usage
4
+
5
+ ### Configuration
6
+
7
+ Set up your token and team (find your token [here](https://idonethis.com/api/token/)):
8
+
9
+ ```
10
+ $ bin/idonethis config user.token=7513375f96b158a5c42a1337f1025d4d76d1deb
11
+ ```
12
+
13
+ ```
14
+ $ bin/idonethis config user.team=benbiddington-personal
15
+ ```
16
+
17
+ ### List dones
18
+
19
+ ```
20
+ $ bin/idonethis list today
21
+ 1 2015-09-21T04:42:21.832 -- Moved settings file into lib
22
+ 2 2015-09-21T01:22:53.058 -- Some more refactoring
23
+ 3 2015-09-21T01:13:00.111 -- [idone] Split adapters and use cases
24
+ 4 2015-09-20T23:29:01.002 -- Some work in change contact (js)
25
+ 5 2015-09-20T21:47:00.903 -- Do <code>backticks</code> work?
26
+ 6 2015-09-20T21:46:00.053 -- Seems to work on windows, though we do get that gem warning &lt;Unresolved specs during Gem::Specification.reset&gt;
27
+ ```
28
+
29
+ ### Add done
30
+
31
+ ```
32
+ $ bin/idonethis new -m "Ricky Bizzness"
33
+ ```
34
+
35
+
36
+ ## Development
37
+
38
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
39
+
40
+ 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).
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/idonethis-cli.
45
+
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
50
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "idonethis/cli"
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/idonethis ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "idonethis"
5
+
6
+ Idonethis::Adapters::Cli.run ARGV
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
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'idonethis/cli/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "idonethis-cli"
8
+ spec.version = Idonethis::Cli::VERSION
9
+ spec.authors = ["Ben Biddington"]
10
+ spec.email = ["ben.biddington@gmail.com"]
11
+
12
+ spec.summary = %q{Command line interface for idonethis}
13
+ spec.description = %q{Command line interface for idonethis}
14
+ spec.homepage = ""
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 = "bin"
27
+ spec.executables = ['idonethis']
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler" , "~> 1.10"
31
+ spec.add_development_dependency "rake" , "~> 10.0"
32
+ spec.add_dependency "rest-client" , "~> 1"
33
+ end
@@ -0,0 +1,68 @@
1
+ require 'internet'
2
+ require 'views/cli'
3
+ require 'use_cases/new'
4
+ require 'use_cases/list'
5
+ require 'settings_file'
6
+
7
+ module Idonethis::Adapters
8
+ class Cli
9
+ class << self
10
+ def run(argv={})
11
+ args = parse(argv)
12
+
13
+ command,*rest = argv
14
+
15
+ args.merge!({ opts: rest, log: log, internet: Idonethis::Adapters::Internet, view: Idonethis::Adapters::Views::Cli::List.method(:apply)})
16
+ credential = Settings.credential
17
+
18
+ log.call "args: #{args}, command: #{command}, rest: #{rest}"
19
+
20
+ use_cases = {
21
+ list: Idonethis::UseCases::List.method(:apply),
22
+ new: Idonethis::UseCases::New.method(:apply),
23
+ config: Idonethis::UseCases::Config.method(:apply),
24
+ help: ->(credential, args) { puts "TODO: implement help" }
25
+ }
26
+
27
+ use_case = use_cases[command.to_sym]
28
+
29
+ unless use_case
30
+ puts "No command <#{command.to_sym}> found"
31
+ return
32
+ end
33
+
34
+ use_case.call credential, args
35
+ end
36
+
37
+ private
38
+
39
+ def log
40
+ @log ||= ENV.include?("LOG") ? ->(msg){puts "[LOG] #{msg}"} : ->(_){}
41
+ end
42
+
43
+ def parse(argv={})
44
+ args = {}
45
+
46
+ require 'optparse'
47
+
48
+ OptionParser.new do |opts|
49
+ opts.banner = "Usage: command [options]"
50
+
51
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
52
+ args[:verbose] = v
53
+ end
54
+
55
+ opts.on("-m MESSAGE", "Message") do |m|
56
+ args[:message] = m
57
+ end
58
+
59
+ opts.on("-d", "Dry run") do |_|
60
+ args[:dry_run] = true
61
+ end
62
+ end.parse!
63
+
64
+ args
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,15 @@
1
+ module Idonethis::Adapters
2
+ module Internet
3
+ class << self
4
+ require 'restclient'
5
+
6
+ def get(url, headers = {}, body = {})
7
+ RestClient.get(url, headers)
8
+ end
9
+
10
+ def post(url, headers = {}, body = {})
11
+ RestClient.post(url, body, headers)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ module Idonethis::Adapters
2
+ module Settings
3
+ class << self
4
+ def credential
5
+ from_disk || from_env
6
+ end
7
+
8
+ private
9
+
10
+ def from_disk
11
+ require 'yaml'
12
+ YAML.load_file Idonethis::SettingsFile.path if Idonethis::SettingsFile.exists?
13
+ end
14
+
15
+ def from_env
16
+ { token: ENV["TOKEN"], team: ENV["TEAM"] }
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ module Idonethis::Adapters
2
+ module Views
3
+ module Cli
4
+ module List
5
+ class << self
6
+ def apply(dones=[])
7
+ dones.select{|it| it["is_goal"] == false}.each_with_index do |d,i|
8
+ #{
9
+ # "id"=>22609300, "created"=>"2015-09-09T06:26:07.120", "updated"=>"2015-09-19T13:00:03.570", "markedup_text"=>"fix api smoke", "done_date"=>"2015-09-20", "owner"=>"ben.biddington",
10
+ # "team_short_name"=>"benbiddington-personal", "tags"=>[], "likes"=>[], "comments"=>[], "meta_data"=>{}, "is_goal"=>true, "goal_completed"=>false,
11
+ # "url"=>"https://idonethis.com/api/v0.1/dones/22609300/", "team"=>"https://idonethis.com/api/v0.1/teams/benbiddington-personal/", "raw_text"=>"[ ] fix api smoke", "permalink"=>"https://idonethis.com/done/22609300/"}
12
+ # puts d.inspect
13
+ printf("%-5s", i+1); puts %Q{#{d["created"]} -- #{d["markedup_text"].slice(0,150)}}
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ module Idonethis
2
+ module Cli
3
+ VERSION = "0.2.0"
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ module Idonethis
2
+ module Index
3
+ class << self
4
+ def dones(params={})
5
+ %Q{#{dones_base_earl}?#{params.map{|k,v| "#{k}=#{v}"}.join('&')}}
6
+ end
7
+
8
+ private
9
+
10
+ def dones_base_earl
11
+ "https://idonethis.com/api/v0.1/dones/"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module Idonethis
2
+ class SettingsFile
3
+ class << self
4
+ def exists?; File.exists?(path); end
5
+
6
+ def path
7
+ @@path ||= File.expand_path("~/.idonethis.settings")
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,40 @@
1
+ module Idonethis::UseCases
2
+ module Config
3
+ class << self
4
+ def apply(_, args={})
5
+ log = args[:log] || fail("You need to supply :log adapter")
6
+
7
+ log.call "args: #{args}"
8
+
9
+ require 'yaml'
10
+
11
+ settings = File.exists?(filename) ? YAML.load_file(filename) : {}
12
+
13
+ token = (args[:opts].map{|it| it.match /user.token=(.+)/}.compact || []).first
14
+
15
+ if token
16
+ File.open filename, "w+" do |f|
17
+ f.puts(settings.merge({token: token[1]}).to_yaml)
18
+ end
19
+ end
20
+
21
+ team = (args[:opts].map{|it| it.match /user.team=(.+)/}.compact || []).first
22
+
23
+ if team
24
+ File.open filename, "w+" do |f|
25
+ f.puts(settings.merge({team: team[1]}).to_yaml)
26
+ end
27
+ end
28
+
29
+ puts "Settings saved to <#{filename}>"
30
+ end
31
+
32
+ private
33
+
34
+ def filename
35
+ require 'settings_file'
36
+ Idonethis::SettingsFile.path
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,55 @@
1
+ module Idonethis::UseCases
2
+ module List
3
+ class << self
4
+ def apply(credential, args={})
5
+ log = args[:log] || fail("You need to supply :log adapter")
6
+ view = args[:view] || fail("You need to supply :view adapter")
7
+
8
+ list = get(credential, log, args).tap{|result| log.call(result)}
9
+
10
+ view.call list
11
+ end
12
+
13
+ private
14
+
15
+ def get(credential, log, args)
16
+ result = []
17
+ page = 1
18
+
19
+ loop do
20
+ reply = get_page(page, credential, log, args)
21
+
22
+ result += reply["results"]
23
+
24
+ page += 1
25
+
26
+ break if reply["next"].nil?
27
+ end
28
+
29
+ result
30
+ end
31
+
32
+ def get_page(page, credential, log, args) # https://idonethis.com/api/v0.1/dones/
33
+ params = {"order_by" => "-created", "page_size" => 100, "page" => page}
34
+
35
+ if args[:opts].include?("today")
36
+ params ["done_date"] = "today"
37
+ end
38
+
39
+ url = Idonethis::Index.dones(params)
40
+
41
+ log.call "url: #{url}"
42
+
43
+ internet = args[:internet] || fail("You need to supply :internet adapter")
44
+
45
+ parse internet.get(url, { "Authorization" => "Token #{credential[:token]}", accept: "application/json"})
46
+ end
47
+
48
+ def parse(reply)
49
+ require 'json'
50
+
51
+ JSON.parse(reply.body)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,25 @@
1
+ module Idonethis::UseCases
2
+ module New
3
+ class << self
4
+ def apply(credential, args={})
5
+ log = args[:log] || fail("You need to supply :internet adapter")
6
+ internet = args[:internet] || fail("You need to supply :internet adapter")
7
+
8
+ log.call "args: #{args}"
9
+
10
+ parse internet.post(
11
+ Idonethis::Index.dones,
12
+ { "Authorization" => "Token #{credential[:token]}", accept: "application/json"},
13
+ { "raw_text" => args[:message], "team" => credential[:team]})
14
+ end
15
+
16
+ private
17
+
18
+ def parse(reply)
19
+ require 'json'
20
+
21
+ JSON.parse(reply.body)
22
+ end
23
+ end
24
+ end
25
+ end
data/lib/idonethis.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "idonethis/cli/version"
2
+
3
+ lib = File.expand_path(File.join(File.dirname(__FILE__), "idonethis"))
4
+ adapters = File.expand_path(File.join(File.dirname(__FILE__), "adapters"))
5
+
6
+ $:.unshift lib
7
+ $:.unshift adapters
8
+
9
+ Dir.glob(File.join(lib, "**", "*.rb")).each {|file| require file}
10
+ Dir.glob(File.join(adapters, "**", "*.rb")).each {|file| require file}
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: idonethis-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Ben Biddington
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1'
55
+ description: Command line interface for idonethis
56
+ email:
57
+ - ben.biddington@gmail.com
58
+ executables:
59
+ - idonethis
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/idonethis
71
+ - bin/setup
72
+ - idonethis-cli.gemspec
73
+ - lib/adapters/cli.rb
74
+ - lib/adapters/internet.rb
75
+ - lib/adapters/settings.rb
76
+ - lib/adapters/views/cli.rb
77
+ - lib/idonethis.rb
78
+ - lib/idonethis/cli/version.rb
79
+ - lib/idonethis/index.rb
80
+ - lib/idonethis/settings_file.rb
81
+ - lib/idonethis/use_cases/config.rb
82
+ - lib/idonethis/use_cases/list.rb
83
+ - lib/idonethis/use_cases/new.rb
84
+ homepage: ''
85
+ licenses:
86
+ - MIT
87
+ metadata:
88
+ allowed_push_host: https://rubygems.org
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.4.8
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Command line interface for idonethis
109
+ test_files: []