nearmiss-ruby 1.0.3 → 1.0.4
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 +4 -4
- data/Makefile +15 -0
- data/lib/nearmiss-ruby/client/attachments.rb +88 -0
- data/lib/nearmiss-ruby/client/comments.rb +0 -0
- data/lib/nearmiss-ruby/client/companies.rb +76 -0
- data/lib/nearmiss-ruby/incident.rb +75 -0
- data/lib/nearmiss-ruby/project.rb +75 -0
- data/lib/nearmiss-ruby/version.rb +1 -1
- data/script/bootstrap +5 -0
- data/script/cibuild +5 -0
- data/script/console +11 -0
- data/script/package +7 -0
- data/script/release +16 -0
- data/script/test +0 -0
- metadata +13 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02345c1b1ede0a30870db477c456afacb9e3efeb
|
4
|
+
data.tar.gz: 687b821cce247887aa3844a44e2a43de66e9822d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca6c040381a5176edfe8c3a46f234260d05b6920485c6bb5ef13f1631e689c65b7a39fb7b4f53d8e63e5d888df7f0da1f55e8b00e9d6e492b6e3509c6ce90ecd
|
7
|
+
data.tar.gz: f02804f0c4a88fd0d7c706e4e0e70dd6e30a65a315eb2543ce7fa9498ee960bc604ac8bbecddfe996851f23c83fe713ae83ee251b4eca8a96bbc8cf2f318ecfb
|
data/Makefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
install:
|
2
|
+
bundle exec rake install
|
3
|
+
|
4
|
+
test-install:
|
5
|
+
bundle install
|
6
|
+
|
7
|
+
test:
|
8
|
+
bundle exec rake spec
|
9
|
+
|
10
|
+
authors:
|
11
|
+
echo "Authors\n=======\n\nA huge thanks to all of our contributors:\n\n" > AUTHORS.md
|
12
|
+
git log --raw | grep "^Author: " | cut -d ' ' -f2- | cut -d '<' -f1 | sed 's/^/- /' | sort | uniq >> AUTHORS.md
|
13
|
+
|
14
|
+
deploy:
|
15
|
+
bundle exec rake build | sed -e 's/.*pkg/pkg/g' | sed -e "s/\.$$//g" | xargs gem push
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Nearmiss
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# Methods for the Attachments API
|
5
|
+
#
|
6
|
+
module Attachments
|
7
|
+
|
8
|
+
# List nearmiss attachments
|
9
|
+
#
|
10
|
+
# @return [Array<Sawyer::Resource>] List of attachments
|
11
|
+
#
|
12
|
+
def attachments(options = {})
|
13
|
+
since = options[:since] || options["since"]
|
14
|
+
|
15
|
+
options.merge!(since: iso8601(parse_date(since))) if since
|
16
|
+
|
17
|
+
paginate "attachments", options
|
18
|
+
end
|
19
|
+
alias :list_attachments :attachments
|
20
|
+
|
21
|
+
# Get a single attachment
|
22
|
+
#
|
23
|
+
# @param attachment [String] ID of attachment to fetch
|
24
|
+
# @return [Sawyer::Resource] Incident information
|
25
|
+
#
|
26
|
+
def attachment(attachment, options = {})
|
27
|
+
get "attachments/#{attachment}", options
|
28
|
+
end
|
29
|
+
|
30
|
+
# Project attachments
|
31
|
+
#
|
32
|
+
# @param project [String, Hash, Incident] Incident
|
33
|
+
# @return [Sawyer::Resource] Incident information
|
34
|
+
#
|
35
|
+
def incident_attachments(incident, options = {})
|
36
|
+
|
37
|
+
paginate "#{Incident.new(incident).path}/attachments", options
|
38
|
+
|
39
|
+
end
|
40
|
+
alias :nearmiss_attachments :incident_attachments
|
41
|
+
|
42
|
+
|
43
|
+
# Create an attachment
|
44
|
+
#
|
45
|
+
# @param options [Hash] Attachment information.
|
46
|
+
# @option options [String] :created_by_id Id of person who created this attachment
|
47
|
+
# @option options [String] :original_filename title of file
|
48
|
+
# @option options [String] :content_type e.g. `image/jpeg`
|
49
|
+
# @option options [String] :attachable_id associated ID of resource this attachment belongs to
|
50
|
+
# @option options [String] :attachable_type e.g. Incident
|
51
|
+
|
52
|
+
#
|
53
|
+
# @return [Sawyer::Resource] Newly created attachment info
|
54
|
+
def create_attachment(options = {})
|
55
|
+
post 'attachments', options
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def update_attachment(attachment, options = {})
|
60
|
+
patch "attachments/#{attachment}", options
|
61
|
+
end
|
62
|
+
alias :edit_attachment :update_attachment
|
63
|
+
|
64
|
+
|
65
|
+
protected
|
66
|
+
|
67
|
+
def iso8601(date)
|
68
|
+
if date.respond_to?(:iso8601)
|
69
|
+
date.iso8601
|
70
|
+
else
|
71
|
+
date.strftime("%Y-%m-%dT%H:%M:%S%Z")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
# Parses the given string representation of a date, throwing a meaningful exception
|
75
|
+
# (containing the date that failed to parse) in case of failure.
|
76
|
+
#
|
77
|
+
# @param date [String] String representation of a date
|
78
|
+
# @return [DateTime]
|
79
|
+
def parse_date(date)
|
80
|
+
date = DateTime.parse(date.to_s)
|
81
|
+
rescue ArgumentError
|
82
|
+
raise ArgumentError, "#{date} is not a valid date"
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
File without changes
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Nearmiss
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# Methods for the Companies API
|
5
|
+
#
|
6
|
+
module Companies
|
7
|
+
|
8
|
+
# List companies
|
9
|
+
#
|
10
|
+
# @note Shows a list of companies for the users organization aka account
|
11
|
+
#
|
12
|
+
# @return [Array<Sawyer::Resource>] List of companys
|
13
|
+
def companies(options = {})
|
14
|
+
paginate "companies", options
|
15
|
+
end
|
16
|
+
alias :list_companies :companies
|
17
|
+
|
18
|
+
# Get a single company
|
19
|
+
#
|
20
|
+
# @param company [String] UUID of company to fetch
|
21
|
+
# @return [Sawyer::Resource] Project information
|
22
|
+
#
|
23
|
+
def company(company, options = {})
|
24
|
+
get "#{company_path(company)}", options
|
25
|
+
end
|
26
|
+
|
27
|
+
# Create a company
|
28
|
+
#
|
29
|
+
# @param options [Hash] Project information.
|
30
|
+
# @option options [String] :name e.g. Berkeley Art Museum
|
31
|
+
# @option options [String] :company_id e.g. 10611.70
|
32
|
+
# @return [Sawyer::Resource] Newly created company info
|
33
|
+
def create_company(options = {})
|
34
|
+
post 'companies', options
|
35
|
+
end
|
36
|
+
|
37
|
+
# Edit a company
|
38
|
+
#
|
39
|
+
# @param options [Hash] Project information.
|
40
|
+
# @option options [String] :name e.g. Berkeley Art Museum
|
41
|
+
# @option options [String] :company_id e.g. 10611.70
|
42
|
+
#
|
43
|
+
# @return
|
44
|
+
# [Sawyer::Resource] Newly created company info
|
45
|
+
# @example Update a company
|
46
|
+
# @client.edit_company('some_id', {
|
47
|
+
# name: "New name of company",
|
48
|
+
# company_id: "1043.32"
|
49
|
+
# })
|
50
|
+
#
|
51
|
+
def edit_company(company, options = {})
|
52
|
+
patch "#{company_path(company)}", options
|
53
|
+
end
|
54
|
+
|
55
|
+
# Delete a company
|
56
|
+
#
|
57
|
+
# @param company [String] Project ID
|
58
|
+
# @return [Boolean] Indicating success of deletion
|
59
|
+
#
|
60
|
+
def delete_company(company, options = {})
|
61
|
+
boolean_from_response :delete, "companies/#{company}", options
|
62
|
+
end
|
63
|
+
alias :remove_company :delete_company
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def company_path(id)
|
68
|
+
if uuid?(id)
|
69
|
+
"companies/#{id}"
|
70
|
+
else
|
71
|
+
"company/#{id}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Nearmiss
|
2
|
+
|
3
|
+
# Class to parse incident owner and name from
|
4
|
+
# URLs and to generate URLs
|
5
|
+
class Incident
|
6
|
+
attr_accessor :id
|
7
|
+
|
8
|
+
# Instantiate from a incident URL
|
9
|
+
#
|
10
|
+
# @return [Incident]
|
11
|
+
def self.from_url(url)
|
12
|
+
Incident.new(URI.parse(url).path[1..-1])
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
def initialize(incident)
|
17
|
+
case incident
|
18
|
+
# when Integer
|
19
|
+
# @id = incident
|
20
|
+
when String
|
21
|
+
@id = incident
|
22
|
+
# @owner, @name = repo.split('/')
|
23
|
+
# unless @owner && @name
|
24
|
+
# raise ArgumentError, "Invalid Incident. Use user/repo format."
|
25
|
+
# end
|
26
|
+
when Incident
|
27
|
+
@id = incident.id
|
28
|
+
# @name = repo.name
|
29
|
+
when Hash
|
30
|
+
@id = incident[:incident] ||= incident[:id]
|
31
|
+
# @owner = repo[:owner] ||= repo[:user] ||= repo[:username]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Incident owner/name
|
36
|
+
# @return [String]
|
37
|
+
def slug
|
38
|
+
# "#{@owner}/#{@name}"
|
39
|
+
end
|
40
|
+
alias :to_s :slug
|
41
|
+
|
42
|
+
# @return [String] Incident API path
|
43
|
+
def path
|
44
|
+
# return named_api_path if @owner && @name
|
45
|
+
return id_api_path if @id
|
46
|
+
end
|
47
|
+
|
48
|
+
# Get the api path for a repo
|
49
|
+
# @param incident [Integer, String, Hash, Incident] A incident.
|
50
|
+
# @return [String] Api path.
|
51
|
+
def self.path(incident)
|
52
|
+
new(incident).path
|
53
|
+
end
|
54
|
+
|
55
|
+
# @return [String] Api path for owner/name identified repos
|
56
|
+
# def named_api_path
|
57
|
+
# "repos/#{slug}"
|
58
|
+
# end
|
59
|
+
|
60
|
+
# @return [String] Api path for id identified incidents
|
61
|
+
def id_api_path
|
62
|
+
"incidents/#{@id}"
|
63
|
+
end
|
64
|
+
|
65
|
+
# Incident URL based on {Nearmiss::Client#web_endpoint}
|
66
|
+
# @return [String]
|
67
|
+
# def url
|
68
|
+
# "#{Octokit.web_endpoint}#{slug}"
|
69
|
+
# end
|
70
|
+
|
71
|
+
# alias :user :owner
|
72
|
+
# alias :username :owner
|
73
|
+
# alias :repo :name
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Nearmiss
|
2
|
+
|
3
|
+
# Class to parse GitHub repository owner and name from
|
4
|
+
# URLs and to generate URLs
|
5
|
+
class Project
|
6
|
+
attr_accessor :owner, :name, :id
|
7
|
+
|
8
|
+
# Instantiate from a GitHub repository URL
|
9
|
+
#
|
10
|
+
# @return [Repository]
|
11
|
+
def self.from_url(url)
|
12
|
+
Project.new(URI.parse(url).path[1..-1])
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
def initialize(project)
|
17
|
+
case project
|
18
|
+
# when Integer
|
19
|
+
# @id = project
|
20
|
+
when String
|
21
|
+
@id = project
|
22
|
+
# @owner, @name = repo.split('/')
|
23
|
+
# unless @owner && @name
|
24
|
+
# raise ArgumentError, "Invalid Repository. Use user/repo format."
|
25
|
+
# end
|
26
|
+
when Project
|
27
|
+
@id = project.id
|
28
|
+
# @name = repo.name
|
29
|
+
when Hash
|
30
|
+
@id = project[:project] ||= project[:id]
|
31
|
+
# @owner = repo[:owner] ||= repo[:user] ||= repo[:username]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Project owner/name
|
36
|
+
# @return [String]
|
37
|
+
def slug
|
38
|
+
# "#{@owner}/#{@name}"
|
39
|
+
end
|
40
|
+
alias :to_s :slug
|
41
|
+
|
42
|
+
# @return [String] Project API path
|
43
|
+
def path
|
44
|
+
# return named_api_path if @owner && @name
|
45
|
+
return id_api_path if @id
|
46
|
+
end
|
47
|
+
|
48
|
+
# Get the api path for a repo
|
49
|
+
# @param project [Integer, String, Hash, Project] A project.
|
50
|
+
# @return [String] Api path.
|
51
|
+
def self.path(project)
|
52
|
+
new(project).path
|
53
|
+
end
|
54
|
+
|
55
|
+
# @return [String] Api path for owner/name identified repos
|
56
|
+
# def named_api_path
|
57
|
+
# "repos/#{slug}"
|
58
|
+
# end
|
59
|
+
|
60
|
+
# @return [String] Api path for id identified repos
|
61
|
+
def id_api_path
|
62
|
+
"projects/#{@id}"
|
63
|
+
end
|
64
|
+
|
65
|
+
# Project URL based on {Nearmiss::Client#web_endpoint}
|
66
|
+
# @return [String]
|
67
|
+
def url
|
68
|
+
# "#{Octokit.web_endpoint}#{slug}"
|
69
|
+
end
|
70
|
+
|
71
|
+
# alias :user :owner
|
72
|
+
# alias :username :owner
|
73
|
+
# alias :repo :name
|
74
|
+
end
|
75
|
+
end
|
data/script/bootstrap
ADDED
data/script/console
ADDED
data/script/package
ADDED
data/script/release
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
# Usage: script/release
|
3
|
+
# Build the package, tag a commit, push it to origin, and then release the
|
4
|
+
# package publicly.
|
5
|
+
|
6
|
+
set -e
|
7
|
+
|
8
|
+
version="$(script/package | grep Version: | awk '{print $2}')"
|
9
|
+
[ -n "$version" ] || exit 1
|
10
|
+
|
11
|
+
echo $version
|
12
|
+
git commit --allow-empty -a -m "Release $version"
|
13
|
+
git tag "v$version"
|
14
|
+
git push origin
|
15
|
+
git push origin "v$version"
|
16
|
+
gem push pkg/*-${version}.gem
|
data/script/test
ADDED
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nearmiss-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Markus Klooth
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- CHANGELOG.md
|
64
64
|
- Gemfile
|
65
65
|
- LICENSE
|
66
|
+
- Makefile
|
66
67
|
- README.md
|
67
68
|
- Rakefile
|
68
69
|
- lib/nearmiss-ruby.rb
|
@@ -70,8 +71,11 @@ files:
|
|
70
71
|
- lib/nearmiss-ruby/authentication.rb
|
71
72
|
- lib/nearmiss-ruby/client.rb
|
72
73
|
- lib/nearmiss-ruby/client/account.rb
|
74
|
+
- lib/nearmiss-ruby/client/attachments.rb
|
73
75
|
- lib/nearmiss-ruby/client/bookmarks.rb
|
74
76
|
- lib/nearmiss-ruby/client/categories.rb
|
77
|
+
- lib/nearmiss-ruby/client/comments.rb
|
78
|
+
- lib/nearmiss-ruby/client/companies.rb
|
75
79
|
- lib/nearmiss-ruby/client/incidents.rb
|
76
80
|
- lib/nearmiss-ruby/client/notifications.rb
|
77
81
|
- lib/nearmiss-ruby/client/projects.rb
|
@@ -80,12 +84,20 @@ files:
|
|
80
84
|
- lib/nearmiss-ruby/configurable.rb
|
81
85
|
- lib/nearmiss-ruby/default.rb
|
82
86
|
- lib/nearmiss-ruby/error.rb
|
87
|
+
- lib/nearmiss-ruby/incident.rb
|
88
|
+
- lib/nearmiss-ruby/project.rb
|
83
89
|
- lib/nearmiss-ruby/raise_error.rb
|
84
90
|
- lib/nearmiss-ruby/rate_limit.rb
|
85
91
|
- lib/nearmiss-ruby/response.rb
|
86
92
|
- lib/nearmiss-ruby/util.rb
|
87
93
|
- lib/nearmiss-ruby/version.rb
|
88
94
|
- nearmiss-ruby.gemspec
|
95
|
+
- script/bootstrap
|
96
|
+
- script/cibuild
|
97
|
+
- script/console
|
98
|
+
- script/package
|
99
|
+
- script/release
|
100
|
+
- script/test
|
89
101
|
homepage: https://github.com/nearmiss/nearmiss-ruby
|
90
102
|
licenses:
|
91
103
|
- MIT
|