yapt 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7f3d3e6e3a120cd87f9c1cc545edd9ac08eb22ac
4
+ data.tar.gz: 2257eedb5a60cc3bc2ee63cf40c878c92f9e9ec6
5
+ SHA512:
6
+ metadata.gz: 839df234bc2acc4db310d0abc5994a505dfb3ce95902e572b0a62d5bbbe7a0afa51d1935cf2520cd07b15098f9484e1e2f68b6eab4512db68e211b8da15b70e6
7
+ data.tar.gz: 9aecd0b88395d255541d8b39361a3c9cc69af75a3c43dd588bd6df64581b65be57f772530a0b63646079d1bbd9bc0fc99ba67c7a17fba3995d62dfaac0c466b8
data/.gitignore ADDED
@@ -0,0 +1,19 @@
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
+ .env
19
+ .yapt_member_cache
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in yapt.gemspec
4
+ gemspec
5
+
6
+ gem "dotenv"
7
+ gem "pry"
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Sam Schenkman-Moore
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.
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # Yapt
2
+
3
+ A command line Pivotal Tracker client. In early days.
4
+
5
+ ## Installation
6
+
7
+ $ gem install yapt
8
+
9
+ ## Usage
10
+
11
+ Environment variables:
12
+
13
+ * api_token
14
+ * project_id
15
+
16
+ yapt list "created_since=last friday" limit=5 keyword
17
+
18
+ ## Contributing
19
+
20
+ 1. Fork it
21
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
22
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
23
+ 4. Push to the branch (`git push origin my-new-feature`)
24
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/yapt ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ require 'boson/runner'
3
+ require "yapt"
4
+
5
+
6
+ Yapt::Runner.start
@@ -0,0 +1,78 @@
1
+ require 'pry'
2
+ require "chronic"
3
+
4
+ module Yapt
5
+ class Filter
6
+ def self.parse(args)
7
+ args.inject({filter: ""}) do |query, arg|
8
+ filter = new(arg)
9
+ # binding.pry
10
+ if filter.filter?
11
+ query[:filter] += "#{filter.to_filter} "
12
+ else
13
+ query[filter.key] = filter.val
14
+ end
15
+ query
16
+ end
17
+ end
18
+
19
+ def filter?
20
+ not %w(limit offset).include?(key)
21
+ end
22
+
23
+ attr_reader :key, :val
24
+ def initialize(a,b=nil)
25
+ if b
26
+ @key, @val = a.to_s, b.to_s
27
+ else
28
+ k, v = a.split(/[:=]/)
29
+ v ? (@key, @val = k, v) : @val = k
30
+ end
31
+ clean_key!
32
+ clean_val!
33
+ end
34
+
35
+ def keyword?
36
+ !key
37
+ end
38
+
39
+ def to_filter
40
+ keyword? ? val : coloned
41
+ end
42
+
43
+ private
44
+
45
+ def coloned
46
+ %{#{key}:"#{val}"}
47
+ end
48
+
49
+ def clean_key!
50
+ # ???
51
+ end
52
+
53
+ def clean_val!
54
+ if val
55
+ if time_filter_fields.include?(key)
56
+ @val = dated(Chronic.parse(val))
57
+ end
58
+ end
59
+ end
60
+
61
+ def time_filter_fields
62
+ @time_filter_fields ||= %w(created modified updated accepted).collect do |event|
63
+ ["", "on", "since", "before"].collect do |timing|
64
+ "#{event}_#{timing}".sub(/_\Z/,'')
65
+ end
66
+ end.flatten
67
+ end
68
+
69
+ def dated(time)
70
+ Date.parse(time.strftime('%Y/%m/%d'))
71
+ end
72
+ # if val
73
+ # if time_filter_fields.include?(key)
74
+ # val = dated(Chronic.parse(val))
75
+ # end
76
+
77
+ end
78
+ end
@@ -0,0 +1,37 @@
1
+ require "yaml"
2
+
3
+ module Yapt
4
+ class Member
5
+ def self.find(id)
6
+ new all.detect {|u| u["person"]["id"] == id }
7
+ end
8
+
9
+ attr_reader :membership
10
+ def initialize(membership)
11
+ @membership = membership
12
+ end
13
+
14
+ def initials
15
+ membership["person"]["initials"]
16
+ end
17
+
18
+ def self.all
19
+ @memberships ||= cache[:results]
20
+ end
21
+
22
+ def self.cache
23
+ if File.exists?(Yapt.tracker_member_cache)
24
+ cache = YAML.load_file(Yapt.tracker_member_cache)
25
+ end
26
+ expires_at = cache ? cache[:expires_at] : Time.new(0)
27
+ expires_at > Time.now ? cache : generate_cache
28
+ end
29
+
30
+ def self.generate_cache
31
+ results = Request.new("memberships").result
32
+ to_cache = { results: results, expires_at: Time.now + Yapt.cache_duration }
33
+ File.open(Yapt.tracker_member_cache, 'w') {|f| f.write to_cache.to_yaml }
34
+ to_cache
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,27 @@
1
+ require "rest-client"
2
+
3
+ module Yapt
4
+ class Request
5
+ def initialize(path, params = {}, method = :get)
6
+ @text_result = send(method, path, params)
7
+ end
8
+
9
+ def result
10
+ JSON.parse(@text_result)
11
+ end
12
+
13
+ def get(path, params={})
14
+ url = "#{base_url}/#{path}"
15
+ RestClient.get url,
16
+ {
17
+ params: params,
18
+ "X-TrackerToken" => Yapt.api_token
19
+ }
20
+ end
21
+
22
+ def base_url
23
+ "https://www.pivotaltracker.com/
24
+ services/v5/projects/#{Yapt.project_id}".gsub(/\s+/,'')
25
+ end
26
+ end
27
+ end
data/lib/yapt/story.rb ADDED
@@ -0,0 +1,11 @@
1
+ module Yapt
2
+ class Story
3
+ def self.find(options = ["limit=5"])
4
+ params = Filter.parse(options)
5
+ puts View.headline(params[:filter])
6
+ puts
7
+ results = Request.new("stories", params, :get).result
8
+ View.display(results)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Yapt
2
+ VERSION = "0.0.1"
3
+ end
data/lib/yapt/view.rb ADDED
@@ -0,0 +1,75 @@
1
+ require "ostruct"
2
+
3
+ module Yapt
4
+ class View
5
+ extend Forwardable
6
+
7
+ def_delegators :@story, :url, :story_type, :description, :id,
8
+ :current_state, :labels, :owned_by_id, :created_at, :kind,
9
+ :project_id, :requested_by_id, :updated_at, :name
10
+
11
+ def self.headline(str)
12
+ "About to display: #{str}"
13
+ end
14
+
15
+ def self.display(stories)
16
+ stories.inject("") do |str, story|
17
+ str + new(story).to_s
18
+ end
19
+ end
20
+
21
+ attr_reader :story
22
+ def initialize(story)
23
+ @story = OpenStruct.new(story)
24
+ end
25
+
26
+ def to_s
27
+ [:id, :story_type, :current_state, :name, :nl,
28
+ :created_at_display, :updated_at_display,
29
+ :owner_initials, :requester_initials,
30
+ :nl, :nl
31
+ ].inject("") do |str, element|
32
+ str += "#{send(element)}"
33
+ element == :nl ? str : "#{str} | "
34
+ end.gsub(/\| $/, '')
35
+ end
36
+
37
+ private
38
+
39
+ def owner_initials
40
+ if owned_by_id
41
+ "Owner: #{Member.find(owned_by_id).initials}"
42
+ else
43
+ "No owner"
44
+ end
45
+ end
46
+
47
+ def requester_initials
48
+ "Requester: #{Member.find(requested_by_id).initials}"
49
+ end
50
+
51
+ def created_at_display
52
+ "Created: #{time_display(created_at)}"
53
+ end
54
+
55
+ def updated_at_display
56
+ "Updated: #{time_display(updated_at)}"
57
+ end
58
+
59
+ def time_display(time)
60
+ Time.parse(time).strftime("%a %d%b %I:%M")
61
+ end
62
+
63
+ def id_name
64
+ "#{story.id} | #{story.name}\n"
65
+ end
66
+
67
+ def nl
68
+ "\n"
69
+ end
70
+ end
71
+ end
72
+ # ["url", "story_type", "description", "id", "current_state",
73
+ # "labels", "owned_by_id", "created_at", "kind", "project_id",
74
+ # "requested_by_id", "updated_at", "name"]
75
+
data/lib/yapt.rb ADDED
@@ -0,0 +1,49 @@
1
+ require 'dotenv'
2
+ Dotenv.load
3
+
4
+ module Yapt
5
+ autoload :VERSION, "yapt/version"
6
+ autoload :Story, "yapt/story"
7
+ autoload :Filter, "yapt/filter"
8
+ autoload :View, "yapt/view"
9
+ autoload :Member, "yapt/member"
10
+ autoload :Request, "yapt/request"
11
+
12
+ def self.project_id
13
+ @project_id ||= ENV['project_id']
14
+ end
15
+
16
+ def self.api_token
17
+ @api_token ||= ENV['api_token']
18
+ end
19
+
20
+ def self.cache_duration
21
+ 3600
22
+ end
23
+
24
+ def self.tracker_member_cache
25
+ File.expand_path "#{Dir.pwd}/.yapt_member_cache"
26
+ end
27
+
28
+ def self.member_lookup(id)
29
+ Member.find(id)
30
+ end
31
+
32
+ class Runner < Boson::Runner
33
+ # option :urgent, type: :boolean
34
+ def list(*args)
35
+ puts
36
+ puts Story.find(args)
37
+ puts
38
+ puts args.inspect
39
+ end
40
+
41
+ def members
42
+ Member.cache
43
+ end
44
+
45
+ def moo
46
+ puts "MOOOO"
47
+ end
48
+ end
49
+ end
data/yapt.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'yapt/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "yapt"
8
+ spec.version = Yapt::VERSION
9
+ spec.authors = ["Sam Schenkman-Moore"]
10
+ spec.email = ["samsm@samsm.com"]
11
+ spec.description = %q{A command line app for navigating Pivotal Tracker. WIP}
12
+ spec.summary = %q{Command line pivotal tracker thing. WIP}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'boson'
22
+ spec.add_dependency 'highline'
23
+ spec.add_dependency 'rest-client'
24
+ spec.add_dependency 'chronic'
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.3"
27
+ spec.add_development_dependency "rake"
28
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yapt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sam Schenkman-Moore
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: boson
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: highline
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: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: chronic
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
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: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
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: A command line app for navigating Pivotal Tracker. WIP
98
+ email:
99
+ - samsm@samsm.com
100
+ executables:
101
+ - yapt
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - .gitignore
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - bin/yapt
111
+ - lib/yapt.rb
112
+ - lib/yapt/filter.rb
113
+ - lib/yapt/member.rb
114
+ - lib/yapt/request.rb
115
+ - lib/yapt/story.rb
116
+ - lib/yapt/version.rb
117
+ - lib/yapt/view.rb
118
+ - yapt.gemspec
119
+ homepage: ''
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.1.11
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Command line pivotal tracker thing. WIP
143
+ test_files: []