hypothesis 0.0.1

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: 9c94a80a10fbaf61310d93b0faeb5d11e32b08d0
4
+ data.tar.gz: f7230d2e87642a4c2e126759f7e3d8ac574f50f1
5
+ SHA512:
6
+ metadata.gz: 6e8a14f333d98897609163da4d16daf3c61a4f28c9508d60e78250a851704cd5563cc1f62a418ef80955309fe808afb04dcfdd259b8c5611ec0e48d05c3ecc7c
7
+ data.tar.gz: bb5691fb09a333d00d39f452dd747d8248e63b6c7b98aaba47a12e403022117a9a507ccb3f3d43c5e72cdebbc93f0ac5334b33350e5f2c72bc6484ed4411ae0a
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ Unofficial [hypothesis](https://hypothes.is) ruby gem.
2
+
3
+ ### Installation
4
+
5
+ ```gem install hypothesis```
6
+
7
+ ### Usage
8
+
9
+ You'll need to generate an API token on your [Hypothesis developer page](https://hypothes.is/account/developer).
10
+
11
+
12
+ ```ruby
13
+ require 'rubygems'
14
+ require 'hypothesis'
15
+
16
+ hypothesis = Hypothesis::API.new('YOUR_HYPOTHESIS_API_KEY')
17
+ puts hypothesis.search({ user: 'javier', limit: 10 })
18
+
19
+ ```
20
+
21
+ That will output a JSON with the found items:
22
+
23
+ ```ruby
24
+ => {"rows"=>[{"updated"=>"2016-08-21T13:08:33.877253+00:00", "group"=>"__world__", "target"=>[{"source"=>"http://thelongandshort.org/society/war-on-cash", "selector"=>[{"endContainer"=>"/main[1]/article[1]/div[1]/div[6]/div[1]/p[3]", "startContainer"=>"/main[1]/article[1]/div[1]/div[6]/div[1]/p[3]", "type"=>"RangeSelector", "startOffset"=>0, "endOffset"=>368}, {"type"=>"TextPositionSelector", "end"=>9811, "start"=>9443}, {"exact"=>"Anyone defending cash in this context will be labelled as an anti-progress, reactionary, and nostalgic Luddite. That's why we must not defend cash. Rather, we should focus on pointing out that the Death of Cash means the Rise of Something Else. We are fighting a broader battle to maintain alternatives to the growing digital panopticon that is emerging all around us.", "prefix"=>"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "type"=>"TextQuoteSelector", "suffix"=>"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}]}], "links"=>{"json"=>"https://hypothes.is/api/annotations/XUdzmGegAeaMle8incguxg", "html"=>"https://hypothes.is/a/XUdzmGegEeaNle8inzguxg", "incontext"=>"https://hyp.is/XUdzmGegAeaMle8incguxg/thelongandshort.org/society/war-on-cash"}, "tags"=>[], "text"=>"", "created"=>"2016-08-21T13:08:33.877245+00:00", "uri"=>"http://thelongandshort.org/society/war-on-cash", "user"=>"acct:javier@hypothes.is", "document"=>{"title"=>["The War on Cash"]}, "id"=>"XUdzmGegAeaMle8incguxg", "permissions"=>{"read"=>["acct:javier@hypothes.is"], "admin"=>["acct:javier@hypothes.is"], "update"=>["acct:javier@hypothes.is"], "delete"=>["acct:javier@hypothes.is"]}}], "total"=>1}
25
+ ```
26
+
27
+ ### API reference
28
+
29
+ [The Hypothesis API](https://h.readthedocs.io/en/latest/api/)
data/bin/hypothesis ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
3
+
4
+ require 'hypothesis'
5
+ Hypothesis::CLI.start(ARGV)
@@ -0,0 +1,43 @@
1
+ require 'logger'
2
+ require 'httparty'
3
+
4
+ module Hypothesis
5
+ class API
6
+ BASE_ENDPOINT = 'https://hypothes.is/api/'.freeze
7
+ SEARCH_ENDPOINT = 'search'.freeze
8
+ ANNOTATIONS_ENDPOINT = 'annotations/'.freeze
9
+
10
+ def initialize(api_key)
11
+ @api_key = api_key
12
+ end
13
+
14
+ def root
15
+ get(BASE_ENDPOINT)
16
+ rescue => e
17
+ { error: e }
18
+ end
19
+
20
+ def search(params = {})
21
+ get(BASE_ENDPOINT + SEARCH_ENDPOINT, params)
22
+ rescue => e
23
+ { error: e }
24
+ end
25
+
26
+ def read(id)
27
+ get(BASE_ENDPOINT + ANNOTATIONS_ENDPOINT + id)
28
+ rescue => e
29
+ { error: e }
30
+ end
31
+
32
+ private
33
+
34
+ def get(url, options = {})
35
+ header = @api_key ? { 'Authorization' => 'Bearer ' + @api_key } : {}
36
+ HTTParty.get(url, query: options, headers: header).parsed_response
37
+ end
38
+
39
+ def log(msg)
40
+ puts msg if Hypothesis.log
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module Hypothesis
2
+ VERSION = '0.0.1'.freeze
3
+ end
data/lib/hypothesis.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require_relative 'hypothesis/version'
3
+ require_relative 'hypothesis/api'
4
+
5
+ module Hypothesis
6
+ class << self
7
+ attr_accessor :log
8
+ attr_accessor :debug
9
+ end
10
+
11
+ self.log = false
12
+ self.debug = false
13
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hypothesis
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Javier Arce
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.5'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 3.5.1
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '3.5'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 3.5.1
61
+ - !ruby/object:Gem::Dependency
62
+ name: rubocop
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.39.0
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.39.0
75
+ - !ruby/object:Gem::Dependency
76
+ name: httparty
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 0.14.0
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 0.14.0
85
+ type: :runtime
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: 0.14.0
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 0.14.0
95
+ description: 'Ruby API for hypothesis '
96
+ email: javierarce@gmail.com
97
+ executables:
98
+ - hypothesis
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - README.md
103
+ - bin/hypothesis
104
+ - lib/hypothesis.rb
105
+ - lib/hypothesis/api.rb
106
+ - lib/hypothesis/version.rb
107
+ homepage: https://github.com/javierarce/hypothesis
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '2.1'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.6.6
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Ruby API for hypothesis
131
+ test_files: []