share_notify 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 992d71908ef077371053a44b67c63bb32fceae00
4
- data.tar.gz: ae4841bd49c0c2f381da680e374684060cfc8004
3
+ metadata.gz: 19538bad0fafdc5a725b731da4c8d5867c902af6
4
+ data.tar.gz: 1d67b18db273434e8f609b95752419e40c1bc2aa
5
5
  SHA512:
6
- metadata.gz: 8970e6026ce4d30738cff7ea4f4914066ad108f8483665ffa4d619c018497049d7d924d3b498826fe7ec69d316e462079b755bd88d75fe8da83182254aacac8f
7
- data.tar.gz: 99efeef394b0ffbfb8c002e30a933b38ee7edcac5bbce895493e02f57d526d4c94a4c240d556da660b56eefe48e4371191dcb3f90bc9e4bf22d750c24138eec3
6
+ metadata.gz: 5e2ea02ee49d794049bd4342444783f7984303894a42b0b061ec82269000d5eca1b7edfe6e0928e540178ed979e5322eb6eea2b3cabb2f79e750e612dd729b87
7
+ data.tar.gz: 3c4071b8d2167cc9235683946300cb9dfe2dcc9a097a36e4c9fb55075bc56bcc763f2c8e3c457e447b8ff7163cf85f15e1f4cb3b633b1a8fffc6b87342c0bbf7
@@ -1,5 +1,3 @@
1
- require: rubocop-rspec
2
-
3
1
  AllCops:
4
2
  DisplayCopNames: true
5
3
  Include:
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in share_notify.gemspec
4
4
  gemspec
5
5
 
6
- gem 'byebug'
6
+ gem 'byebug', require: false
7
7
  gem 'rubocop', require: false
8
- gem 'rubocop-rspec', require: false
8
+ # Removed until https://github.com/nevir/rubocop-rspec/issues/78 is resolved
9
+ #gem 'rubocop-rspec', require: false
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # ShareNotify
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/share_notify.svg)](https://badge.fury.io/rb/share_notify)
4
+ [![Build Status](https://api.travis-ci.org/projecthydra-labs/share_notify.png?branch=master)](https://travis-ci.org/projecthydra-labs/share_notify)
5
+ [![Apache 2.0 License](http://img.shields.io/badge/APACHE2-license-blue.svg)](./LICENSE)
6
+
3
7
  Provides basic tools for creating documents to send to SHARENotify's Push API as well as query for documents
4
8
  using SHARE Search.
5
9
 
@@ -45,6 +49,18 @@ Then send the document to Share using the `API` class:
45
49
  api = ShareNotify::API.new
46
50
  api.post(document.to_share.to_json)
47
51
 
52
+ ### Deleting Data
53
+
54
+ Same as above, but adding an additional "delete" property informs the Share API that this
55
+ document should be delete from the Search API:
56
+
57
+ > document = ShareNotify::PushDocument.new("http://my.document.id/1234")
58
+ > document.title = "Some Title"
59
+ > document.add_contributor(name: "My Name", email: "myemail@example.com")
60
+ > document.delete
61
+ > api = ShareNotify::API.new
62
+ > api.post(document.to_share.to_json)
63
+
48
64
  ### Querying
49
65
 
50
66
  You can query Share's Search API using the terms outlined in <https://osf.io/dajtq/wiki/SHARE%20Search>
@@ -71,7 +87,7 @@ if the document is already present in ShareNotify's Search API.
71
87
  => true
72
88
 
73
89
  Note: It may take 24 hours or more before documents that have been initially pushed to Share will appear
74
- in the Search API.
90
+ in or be deleted from the Search API.
75
91
 
76
92
  ## Contributing
77
93
 
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ RSpec::Core::RakeTask.new(:spec)
6
6
 
7
7
  desc "Run style checker"
8
8
  RuboCop::RakeTask.new(:rubocop) do |task|
9
- task.requires << 'rubocop-rspec'
9
+ # task.requires << 'rubocop-rspec'
10
10
  task.fail_on_error = true
11
11
  end
12
12
 
@@ -8,6 +8,7 @@ module ShareNotify
8
8
  autoload :Metadata, 'share_notify/metadata'
9
9
  autoload :PushDocument, 'share_notify/push_document'
10
10
  autoload :SearchResponse, 'share_notify/search_response'
11
+ autoload :NotificationQueryService, 'share_notify/notification_query_service'
11
12
 
12
13
  class << self
13
14
  def configure(value)
@@ -0,0 +1,10 @@
1
+ module ShareNotify
2
+ class RuntimeError < ::RuntimeError
3
+ end
4
+
5
+ class InitializationError < RuntimeError
6
+ def initialize(context, method_names)
7
+ super("Expected #{context.inspect} to respond to #{method_names.inspect}")
8
+ end
9
+ end
10
+ end
@@ -1,26 +1,17 @@
1
1
  # Queries the SHARE search api for an existing record. This assumes the class into which this
2
2
  # module is included responds to #url and that in turn is mapped to the docID of the Share
3
3
  # document that was originally uploaded via the SHARE push API.
4
+ #
5
+ # @see ShareNotify::NotificationQueryService for details of interface expectations
4
6
  module ShareNotify::Metadata
5
7
  extend ActiveSupport::Concern
8
+ extend Forwardable
6
9
 
7
- def share_notified?
8
- return if response.status != 200
9
- return false if response.count < 1
10
- response.docs.first.doc_id == url
11
- end
12
-
13
- def call
14
- api.search("shareProperties.docID:\"#{url}\"")
15
- end
10
+ def_delegator :notification_query_service, :share_notified?
16
11
 
17
12
  private
18
13
 
19
- def response
20
- @response ||= ShareNotify::SearchResponse.new(call)
21
- end
22
-
23
- def api
24
- @api ||= ShareNotify::API.new
14
+ def notification_query_service
15
+ @notification_query_service ||= ShareNotify::NotificationQueryService.new(self)
25
16
  end
26
17
  end
@@ -0,0 +1,38 @@
1
+ require 'share_notify/exceptions'
2
+
3
+ module ShareNotify
4
+ # Queries the SHARE search api for an existing record. This assumes the class into which this
5
+ # module is included responds to #url and that in turn is mapped to the docID of the Share
6
+ # document that was originally uploaded via the SHARE push API.
7
+ #
8
+ # @see ShareNotify::PushDocument
9
+ class NotificationQueryService
10
+ def initialize(context)
11
+ self.context = context
12
+ end
13
+
14
+ def share_notified?
15
+ response = search("shareProperties.docID:\"#{context.url}\"")
16
+ return if response.status != 200
17
+ return false if response.count < 1
18
+ response.docs.first.doc_id == context.url
19
+ end
20
+
21
+ private
22
+
23
+ def search(string)
24
+ ShareNotify::SearchResponse.new(api.search(string))
25
+ end
26
+
27
+ def api
28
+ ShareNotify::API.new
29
+ end
30
+
31
+ attr_reader :context
32
+
33
+ def context=(input)
34
+ raise ShareNotify::InitializationError.new(input, [:url]) unless input.respond_to?(:url)
35
+ @context = input
36
+ end
37
+ end
38
+ end
@@ -1,12 +1,20 @@
1
1
  module ShareNotify
2
2
  class PushDocument
3
- attr_reader :uris, :contributors, :providerUpdatedDateTime, :version
4
- attr_accessor :title
3
+ attr_reader :uris,
4
+ :contributors,
5
+ :providerUpdatedDateTime,
6
+ :version,
7
+ :publisher,
8
+ :languages,
9
+ :tags,
10
+ :otherProperties
11
+ attr_accessor :title, :description
5
12
 
6
13
  # @param [String] uri that identifies the resource
7
- def initialize(uri)
14
+ def initialize(uri, datetime = nil)
15
+ datetime = (datetime.is_a?(Time) || datetime.is_a?(DateTime)) ? datetime : Time.now
8
16
  @uris = ShareUri.new(uri)
9
- @providerUpdatedDateTime = Time.now.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
17
+ @providerUpdatedDateTime = datetime.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
10
18
  @contributors = []
11
19
  end
12
20
 
@@ -35,10 +43,32 @@ module ShareNotify
35
43
  @contributors << contributor
36
44
  end
37
45
 
46
+ # @param [Hash] publisher containing required keys for publisher
47
+ def publisher=(publisher)
48
+ return false unless publisher.keys.include?(:name)
49
+ @publisher = publisher
50
+ end
51
+
52
+ # @param [Array<String>] languages list of languages
53
+ def languages=(languages)
54
+ return false unless languages.is_a?(Array)
55
+ @languages = languages
56
+ end
57
+
58
+ # @param [Array<String>] tags list of tags
59
+ def tags=(tags)
60
+ return false unless tags.is_a?(Array)
61
+ @tags = tags
62
+ end
63
+
38
64
  def to_share
39
65
  { jsonData: self }
40
66
  end
41
67
 
68
+ def delete
69
+ @otherProperties = [OtherProperty.new("status", status: ["deleted"])]
70
+ end
71
+
42
72
  class ShareUri
43
73
  attr_reader :canonicalUri, :providerUris
44
74
 
@@ -47,5 +77,14 @@ module ShareNotify
47
77
  @providerUris = [uri]
48
78
  end
49
79
  end
80
+
81
+ class OtherProperty
82
+ attr_reader :name, :property
83
+
84
+ def initialize(*args)
85
+ @name = args.shift
86
+ @properties = args.shift
87
+ end
88
+ end
50
89
  end
51
90
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ShareNotify
3
- VERSION = '0.1.1'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
  end
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency 'httparty'
24
24
 
25
25
  spec.add_development_dependency 'bundler', '~> 1.11'
26
+ spec.add_development_dependency 'factory_girl'
26
27
  spec.add_development_dependency 'rake', '~> 10.0'
27
28
  spec.add_development_dependency 'rspec', '~> 3.0'
28
29
  spec.add_development_dependency 'rspec-its'
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.1
4
+ version: 0.2.0
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-04 00:00:00.000000000 Z
11
+ date: 2016-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: factory_girl
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -140,7 +154,9 @@ files:
140
154
  - config/share_notify.yml
141
155
  - lib/share_notify.rb
142
156
  - lib/share_notify/api.rb
157
+ - lib/share_notify/exceptions.rb
143
158
  - lib/share_notify/metadata.rb
159
+ - lib/share_notify/notification_query_service.rb
144
160
  - lib/share_notify/push_document.rb
145
161
  - lib/share_notify/search_response.rb
146
162
  - lib/share_notify/version.rb