share_notify 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +112 -0
- data/.travis.yml +6 -2
- data/Gemfile +2 -0
- data/README.md +66 -10
- data/Rakefile +13 -3
- data/lib/share_notify/api.rb +5 -5
- data/lib/share_notify/push_document.rb +2 -2
- data/lib/share_notify/search_response.rb +12 -12
- data/lib/share_notify/version.rb +2 -1
- data/lib/share_notify.rb +6 -5
- data/share_notify.gemspec +17 -18
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 992d71908ef077371053a44b67c63bb32fceae00
|
4
|
+
data.tar.gz: ae4841bd49c0c2f381da680e374684060cfc8004
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8970e6026ce4d30738cff7ea4f4914066ad108f8483665ffa4d619c018497049d7d924d3b498826fe7ec69d316e462079b755bd88d75fe8da83182254aacac8f
|
7
|
+
data.tar.gz: 99efeef394b0ffbfb8c002e30a933b38ee7edcac5bbce895493e02f57d526d4c94a4c240d556da660b56eefe48e4371191dcb3f90bc9e4bf22d750c24138eec3
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
require: rubocop-rspec
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
DisplayCopNames: true
|
5
|
+
Include:
|
6
|
+
- '**/Rakefile'
|
7
|
+
|
8
|
+
Metrics/LineLength:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
Metrics/AbcSize:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Metrics/CyclomaticComplexity:
|
15
|
+
Exclude:
|
16
|
+
|
17
|
+
Metrics/PerceivedComplexity:
|
18
|
+
Exclude:
|
19
|
+
|
20
|
+
Metrics/MethodLength:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Metrics/ClassLength:
|
24
|
+
Exclude:
|
25
|
+
|
26
|
+
Metrics/ModuleLength:
|
27
|
+
Exclude:
|
28
|
+
|
29
|
+
Style/BlockDelimiters:
|
30
|
+
Exclude:
|
31
|
+
- 'spec/**/*'
|
32
|
+
|
33
|
+
Style/BlockEndNewline:
|
34
|
+
Exclude:
|
35
|
+
- 'spec/**/*'
|
36
|
+
|
37
|
+
Style/MultilineBlockLayout:
|
38
|
+
Exclude:
|
39
|
+
- 'spec/**/*'
|
40
|
+
|
41
|
+
Style/IndentationConsistency:
|
42
|
+
EnforcedStyle: rails
|
43
|
+
|
44
|
+
Style/CollectionMethods:
|
45
|
+
PreferredMethods:
|
46
|
+
collect: 'map'
|
47
|
+
collect!: 'map!'
|
48
|
+
inject: 'reduce'
|
49
|
+
detect: 'find'
|
50
|
+
find_all: 'select'
|
51
|
+
|
52
|
+
Style/WordArray:
|
53
|
+
Enabled: false
|
54
|
+
|
55
|
+
Style/RegexpLiteral:
|
56
|
+
Enabled: false
|
57
|
+
|
58
|
+
Style/StringLiterals:
|
59
|
+
Enabled: false
|
60
|
+
|
61
|
+
Style/ClassAndModuleChildren:
|
62
|
+
Enabled: false
|
63
|
+
|
64
|
+
Style/Documentation:
|
65
|
+
Enabled: false
|
66
|
+
|
67
|
+
Style/HashSyntax:
|
68
|
+
Exclude:
|
69
|
+
|
70
|
+
Style/LineEndConcatenation:
|
71
|
+
Exclude:
|
72
|
+
|
73
|
+
Style/PredicateName:
|
74
|
+
Exclude:
|
75
|
+
|
76
|
+
Style/GlobalVars:
|
77
|
+
Exclude:
|
78
|
+
- 'spec/**/*'
|
79
|
+
|
80
|
+
Style/SingleLineBlockParams:
|
81
|
+
Enabled: false
|
82
|
+
|
83
|
+
Style/ClassVars:
|
84
|
+
Exclude:
|
85
|
+
|
86
|
+
Style/SignalException:
|
87
|
+
Enabled: false
|
88
|
+
|
89
|
+
RSpec/ExampleWording:
|
90
|
+
CustomTransform:
|
91
|
+
be: is
|
92
|
+
have: has
|
93
|
+
not: does not
|
94
|
+
NOT: does NOT
|
95
|
+
IgnoredWords:
|
96
|
+
- only
|
97
|
+
|
98
|
+
RSpec/FilePath:
|
99
|
+
Enabled: false
|
100
|
+
|
101
|
+
RSpec/InstanceVariable:
|
102
|
+
Enabled: false
|
103
|
+
|
104
|
+
RSpec/DescribeClass:
|
105
|
+
Exclude:
|
106
|
+
|
107
|
+
Style/FileName:
|
108
|
+
Exclude:
|
109
|
+
|
110
|
+
Style/VariableName:
|
111
|
+
Exclude:
|
112
|
+
- 'lib/share_notify/push_document.rb'
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# ShareNotify
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Provides basic tools for creating documents to send to SHARENotify's Push API as well as query for documents
|
4
|
+
using SHARE Search.
|
6
5
|
|
7
6
|
## Installation
|
8
7
|
|
@@ -22,20 +21,77 @@ Or install it yourself as:
|
|
22
21
|
|
23
22
|
## Usage
|
24
23
|
|
25
|
-
|
24
|
+
### Configuration
|
25
|
+
|
26
|
+
In order to push data to Share, you will need a token from OSF. Once obtained, you'll put this in a config folder
|
27
|
+
in your Rails application or project as `config/share_notify.yml`:
|
28
|
+
|
29
|
+
---
|
30
|
+
host: "https://osf.io"
|
31
|
+
token: "MY_TOKEN"
|
32
|
+
|
33
|
+
### Pushing Data
|
34
|
+
|
35
|
+
First, create a `PushDocument` with the required metadata:
|
36
|
+
|
37
|
+
> document = ShareNotify::PushDocument.new("http://my.document.id/1234")
|
38
|
+
> document.title = "Some Title"
|
39
|
+
> document.add_contributor(name: "My Name", email: "myemail@example.com")
|
40
|
+
> document.valid?
|
41
|
+
=> true
|
42
|
+
|
43
|
+
Then send the document to Share using the `API` class:
|
44
|
+
|
45
|
+
api = ShareNotify::API.new
|
46
|
+
api.post(document.to_share.to_json)
|
47
|
+
|
48
|
+
### Querying
|
49
|
+
|
50
|
+
You can query Share's Search API using the terms outlined in <https://osf.io/dajtq/wiki/SHARE%20Search>
|
51
|
+
|
52
|
+
api = ShareNotify::API.new
|
53
|
+
api.search([query terms])
|
54
|
+
|
55
|
+
#### Extending Your Classes
|
56
|
+
|
57
|
+
Assuming your data class has a `#url` method, and that url is used to create the initial `PushDocument`
|
58
|
+
that's sent to Share, you can include `ShareNotify::Metadata` to query Share and determine
|
59
|
+
if the document is already present in ShareNotify's Search API.
|
60
|
+
|
61
|
+
class MyDataClass
|
62
|
+
include ShareNotify::Metadata
|
26
63
|
|
27
|
-
|
64
|
+
def url
|
65
|
+
"http://my.document.id/1234"
|
66
|
+
end
|
67
|
+
end
|
28
68
|
|
29
|
-
|
69
|
+
> document = MyDataClass.find("1234")
|
70
|
+
> document.share_notified?
|
71
|
+
=> true
|
30
72
|
|
31
|
-
|
73
|
+
Note: It may take 24 hours or more before documents that have been initially pushed to Share will appear
|
74
|
+
in the Search API.
|
32
75
|
|
33
76
|
## Contributing
|
34
77
|
|
35
|
-
|
78
|
+
### Hydra Developers
|
36
79
|
|
80
|
+
For Hydra developers, or anyone with a signed CLA, please clone the repo and submit PRs via
|
81
|
+
feature branches. If you don't have rights to projecthydra-labs and do have a signed
|
82
|
+
CLA, please send a note to hydra-tech@googlegroups.com.
|
37
83
|
|
38
|
-
|
84
|
+
1. Clone it
|
85
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
86
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
87
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
88
|
+
5. Create a new Pull Request
|
39
89
|
|
40
|
-
|
90
|
+
### Non-Hydra Developers
|
41
91
|
|
92
|
+
Anyone is welcome to use this software and report issues.
|
93
|
+
In order to merge any work contributed, you'll need to sign a contributor license agreement.
|
94
|
+
For more information on signing a CLA, please contact `legal@projecthyra.org`
|
95
|
+
# Project Hydra
|
96
|
+
This software has been developed by and is brought to you by the Hydra community. Learn more at the
|
97
|
+
[Project Hydra website](http://projecthydra.org)
|
data/Rakefile
CHANGED
@@ -1,6 +1,16 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'rubocop/rake_task'
|
3
4
|
|
4
5
|
RSpec::Core::RakeTask.new(:spec)
|
5
6
|
|
6
|
-
|
7
|
+
desc "Run style checker"
|
8
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
9
|
+
task.requires << 'rubocop-rspec'
|
10
|
+
task.fail_on_error = true
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Run continuous integration tests"
|
14
|
+
task ci: [:rubocop, :spec]
|
15
|
+
|
16
|
+
task default: :ci
|
data/lib/share_notify/api.rb
CHANGED
@@ -9,13 +9,13 @@ class ShareNotify::API
|
|
9
9
|
|
10
10
|
attr_reader :headers, :response
|
11
11
|
|
12
|
-
base_uri ShareNotify.config.fetch(
|
12
|
+
base_uri ShareNotify.config.fetch('host', 'https://staging.osf.io')
|
13
13
|
|
14
14
|
# @param [String] token is optional but some actions will not be successful without it
|
15
15
|
def initialize(_token = nil)
|
16
16
|
@headers = {
|
17
|
-
|
18
|
-
|
17
|
+
'Authorization' => "Token #{ShareNotify.config.fetch('token', nil)}",
|
18
|
+
'Content-Type' => 'application/json'
|
19
19
|
}
|
20
20
|
end
|
21
21
|
|
@@ -37,11 +37,11 @@ class ShareNotify::API
|
|
37
37
|
private
|
38
38
|
|
39
39
|
def api_data_point
|
40
|
-
|
40
|
+
'/api/v1/share/data'
|
41
41
|
end
|
42
42
|
|
43
43
|
def api_search_point
|
44
|
-
|
44
|
+
'/api/v1/share/search/'
|
45
45
|
end
|
46
46
|
|
47
47
|
def with_timeout(&_block)
|
@@ -6,7 +6,7 @@ module ShareNotify
|
|
6
6
|
# @param [String] uri that identifies the resource
|
7
7
|
def initialize(uri)
|
8
8
|
@uris = ShareUri.new(uri)
|
9
|
-
@providerUpdatedDateTime = Time.now.utc.strftime(
|
9
|
+
@providerUpdatedDateTime = Time.now.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
|
10
10
|
@contributors = []
|
11
11
|
end
|
12
12
|
|
@@ -21,7 +21,7 @@ module ShareNotify
|
|
21
21
|
# @param [DateTime or Time] time object that can be formatted in to the correct representation
|
22
22
|
def updated=(time)
|
23
23
|
return unless time.respond_to?(:strftime)
|
24
|
-
@providerUpdatedDateTime = time.utc.strftime(
|
24
|
+
@providerUpdatedDateTime = time.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
|
25
25
|
end
|
26
26
|
|
27
27
|
# @param [String] version identifying the version of the resource
|
@@ -5,17 +5,17 @@ module ShareNotify
|
|
5
5
|
|
6
6
|
# @param [HTTParty::Response] response returned from ShareNotify::API
|
7
7
|
def initialize(response)
|
8
|
-
|
8
|
+
fail ArgumentError, 'API response is nil' if response.nil?
|
9
9
|
@status = response.code
|
10
10
|
@response = response.parsed_response
|
11
11
|
end
|
12
12
|
|
13
13
|
def count
|
14
|
-
response.fetch(
|
14
|
+
response.fetch('count', 0)
|
15
15
|
end
|
16
16
|
|
17
17
|
def docs
|
18
|
-
@docs ||= response.fetch(
|
18
|
+
@docs ||= response.fetch('results', []).map { |d| Document.new(d) }
|
19
19
|
end
|
20
20
|
|
21
21
|
class Document
|
@@ -26,45 +26,45 @@ module ShareNotify
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def contributors
|
29
|
-
doc.fetch(
|
29
|
+
doc.fetch('contributors', [])
|
30
30
|
end
|
31
31
|
|
32
32
|
def title
|
33
|
-
doc.fetch(
|
33
|
+
doc.fetch('title', nil)
|
34
34
|
end
|
35
35
|
|
36
36
|
def properties
|
37
|
-
doc.fetch(
|
37
|
+
doc.fetch('shareProperties', nil)
|
38
38
|
end
|
39
39
|
|
40
40
|
def doc_id
|
41
41
|
return if properties.nil?
|
42
|
-
properties.fetch(
|
42
|
+
properties.fetch('docID', nil)
|
43
43
|
end
|
44
44
|
|
45
45
|
def source
|
46
46
|
return if properties.nil?
|
47
|
-
properties.fetch(
|
47
|
+
properties.fetch('source', nil)
|
48
48
|
end
|
49
49
|
|
50
50
|
def updated
|
51
|
-
time_string = doc.fetch(
|
51
|
+
time_string = doc.fetch('providerUpdatedDateTime', nil)
|
52
52
|
return if time_string.nil?
|
53
53
|
Time.parse(time_string)
|
54
54
|
end
|
55
55
|
|
56
56
|
def uris
|
57
|
-
doc.fetch(
|
57
|
+
doc.fetch('uris', nil)
|
58
58
|
end
|
59
59
|
|
60
60
|
def canonical_uri
|
61
61
|
return if uris.nil?
|
62
|
-
uris.fetch(
|
62
|
+
uris.fetch('canonicalUri', nil)
|
63
63
|
end
|
64
64
|
|
65
65
|
def provider_uris
|
66
66
|
return if uris.nil?
|
67
|
-
uris.fetch(
|
67
|
+
uris.fetch('providerUris', [])
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
data/lib/share_notify/version.rb
CHANGED
data/lib/share_notify.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'share_notify/version'
|
2
|
+
require 'active_support'
|
3
3
|
require 'active_support/core_ext'
|
4
|
-
require
|
4
|
+
require 'httparty'
|
5
5
|
|
6
6
|
module ShareNotify
|
7
7
|
autoload :API, 'share_notify/api'
|
@@ -16,7 +16,7 @@ module ShareNotify
|
|
16
16
|
elsif value.is_a?(String)
|
17
17
|
@config = YAML.load(File.read(value))
|
18
18
|
else
|
19
|
-
|
19
|
+
fail InitializationError, "Unrecognized configuration: #{value.inspect}"
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -28,7 +28,8 @@ module ShareNotify
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def root
|
31
|
-
File.dirname(__dir__)
|
31
|
+
return File.dirname(__dir__) unless defined?(Rails)
|
32
|
+
Rails.root
|
32
33
|
end
|
33
34
|
end
|
34
35
|
end
|
data/share_notify.gemspec
CHANGED
@@ -4,29 +4,28 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'share_notify/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'share_notify'
|
8
8
|
spec.version = ShareNotify::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Adam Wead']
|
10
|
+
spec.email = ['amsterdamos@gmail.com']
|
11
11
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
12
|
+
spec.summary = 'Provides basic API integration with ShareNotify'
|
13
|
+
spec.description = 'Provides basic API integration with ShareNotify'
|
14
|
+
spec.homepage = 'https://github.com/projecthydra-labs/share_notify'
|
15
|
+
spec.license = 'APACHE2'
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir =
|
18
|
+
spec.bindir = 'exe'
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = [
|
20
|
+
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.add_dependency
|
23
|
-
spec.add_dependency
|
22
|
+
spec.add_dependency 'activesupport'
|
23
|
+
spec.add_dependency 'httparty'
|
24
24
|
|
25
|
-
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency "webmock"
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
28
|
+
spec.add_development_dependency 'rspec-its'
|
29
|
+
spec.add_development_dependency 'vcr'
|
30
|
+
spec.add_development_dependency 'webmock'
|
32
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: share_notify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Wead
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -131,6 +131,7 @@ extra_rdoc_files: []
|
|
131
131
|
files:
|
132
132
|
- ".gitignore"
|
133
133
|
- ".rspec"
|
134
|
+
- ".rubocop.yml"
|
134
135
|
- ".travis.yml"
|
135
136
|
- Gemfile
|
136
137
|
- LICENSE
|