panoptes-client 0.2.6 → 0.2.7
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/CHANGELOG.md +6 -0
- data/lib/panoptes-client.rb +1 -0
- data/lib/panoptes/client.rb +2 -28
- data/lib/panoptes/client/discussions.rb +19 -0
- data/lib/panoptes/client/version.rb +1 -1
- data/lib/panoptes/concerns/common_client.rb +77 -0
- data/lib/panoptes/talk_client.rb +25 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8dc546adb36b049e8da428336c52673a0d9f983d
|
4
|
+
data.tar.gz: 85649db5d4650c8d9f92dffd5a23ab85ff8db1f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60f2d4972099ce2d3273a4b4da5cfe1941b6d0f62c86d7fa390cf8db304c7a23971886289f1fea5e9d0d0e93ab8723d2b7cd045dda2e652b5ea9c544bfa98663
|
7
|
+
data.tar.gz: ade3768a597807f6fff9fd9636ff892f6c21f86b45c792d83cf6d8310d0038a253b32a3fa09477490825e7ce89734d0495a1994849311429cadf5c88e490229b
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# 0.2.7
|
2
|
+
|
3
|
+
* Add `TalkClient` to interact with the talk api.
|
4
|
+
* Add `client.discussions` to fetch talk discussions for a focus object.
|
5
|
+
* Refactored the client connection code for re-use between talk and panoptes clients.
|
6
|
+
|
1
7
|
# 0.2.6
|
2
8
|
|
3
9
|
* Add `client.workflow` to fetch a specific workflow.
|
data/lib/panoptes-client.rb
CHANGED
data/lib/panoptes/client.rb
CHANGED
@@ -1,8 +1,4 @@
|
|
1
|
-
require
|
2
|
-
require 'faraday_middleware'
|
3
|
-
require 'faraday/panoptes'
|
4
|
-
|
5
|
-
require "panoptes/client/version"
|
1
|
+
require "panoptes/concerns/common_client"
|
6
2
|
require "panoptes/client/me"
|
7
3
|
require "panoptes/client/projects"
|
8
4
|
require "panoptes/client/subjects"
|
@@ -17,6 +13,7 @@ module Panoptes
|
|
17
13
|
class ResourceNotFound < GenericError; end
|
18
14
|
class ServerError < GenericError; end
|
19
15
|
|
16
|
+
include Panoptes::CommonClient
|
20
17
|
include Panoptes::Client::Me
|
21
18
|
include Panoptes::Client::Projects
|
22
19
|
include Panoptes::Client::Subjects
|
@@ -24,29 +21,6 @@ module Panoptes
|
|
24
21
|
include Panoptes::Client::UserGroups
|
25
22
|
include Panoptes::Client::Workflows
|
26
23
|
|
27
|
-
# A client is the main interface to the API.
|
28
|
-
#
|
29
|
-
# @param auth [Hash] Authentication details
|
30
|
-
# * either nothing,
|
31
|
-
# * a hash with +:token+ (an existing OAuth user token),
|
32
|
-
# * or a hash with +:client_id+ and +:client_secret+ (a keypair for an OAuth Application).
|
33
|
-
# @param url [String] Optional override for the API location to use. Defaults to the official production environment.
|
34
|
-
def initialize(auth: {}, url: "https://panoptes.zooniverse.org")
|
35
|
-
@conn = Faraday.new(url: url) do |faraday|
|
36
|
-
case
|
37
|
-
when auth[:token]
|
38
|
-
faraday.request :panoptes_access_token, url: url, access_token: auth[:token]
|
39
|
-
when auth[:client_id] && auth[:client_secret]
|
40
|
-
faraday.request :panoptes_client_credentials, url: url, client_id: auth[:client_id], client_secret: auth[:client_secret]
|
41
|
-
end
|
42
|
-
|
43
|
-
faraday.request :panoptes_api_v1
|
44
|
-
faraday.request :json
|
45
|
-
faraday.response :json
|
46
|
-
faraday.adapter Faraday.default_adapter
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
24
|
def get(path, query = {})
|
51
25
|
response = conn.get("/api" + path, query)
|
52
26
|
handle_response(response)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Panoptes
|
2
|
+
class Client
|
3
|
+
module Discussions
|
4
|
+
# Get list of talk discussions
|
5
|
+
#
|
6
|
+
# @param focus_id [Integer] filter by focussable id
|
7
|
+
# @param focus_type [String] filter by focussable type
|
8
|
+
# @return list of discussions
|
9
|
+
def discussions(focus_id:, focus_type:)
|
10
|
+
query = {}
|
11
|
+
query[:focus_id] = focus_id
|
12
|
+
query[:focus_type] = focus_type
|
13
|
+
|
14
|
+
response = get("/discussions", query)
|
15
|
+
response.fetch("discussions")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'faraday/panoptes'
|
4
|
+
|
5
|
+
require "panoptes/client/version"
|
6
|
+
|
7
|
+
module Panoptes
|
8
|
+
module CommonClient
|
9
|
+
PROD_API_URL = "https://panoptes.zooniverse.org".freeze
|
10
|
+
PROD_TALK_API_URL = "https://talk.zooniverse.org".freeze
|
11
|
+
|
12
|
+
# A client is the main interface to the API.
|
13
|
+
#
|
14
|
+
# @param auth [Hash] Authentication details
|
15
|
+
# * either nothing,
|
16
|
+
# * a hash with +:token+ (an existing OAuth user token),
|
17
|
+
# * or a hash with +:client_id+ and +:client_secret+ (a keypair for an OAuth Application).
|
18
|
+
# @param url [String] API location to use.
|
19
|
+
# @param auth_url [String] Auth API location to use.
|
20
|
+
def initialize(auth: {}, url: PROD_API_URL, auth_url: PROD_API_URL)
|
21
|
+
@conn = Faraday.new(url: url) do |faraday|
|
22
|
+
case
|
23
|
+
when auth[:token]
|
24
|
+
faraday.request :panoptes_access_token,
|
25
|
+
url: auth_url,
|
26
|
+
access_token: auth[:token]
|
27
|
+
when auth[:client_id] && auth[:client_secret]
|
28
|
+
faraday.request :panoptes_client_credentials,
|
29
|
+
url: auth_url,
|
30
|
+
client_id: auth[:client_id],
|
31
|
+
client_secret: auth[:client_secret]
|
32
|
+
end
|
33
|
+
|
34
|
+
faraday.request :panoptes_api_v1
|
35
|
+
faraday.request :json
|
36
|
+
faraday.response :json
|
37
|
+
faraday.adapter Faraday.default_adapter
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Get a path and perform automatic depagination
|
42
|
+
def paginate(path, query, resource: nil)
|
43
|
+
resource = path.split("/").last if resource.nil?
|
44
|
+
data = last_response = get(path, query)
|
45
|
+
|
46
|
+
while next_path = last_response["meta"][resource]["next_href"]
|
47
|
+
last_response = get(next_path, query)
|
48
|
+
if block_given?
|
49
|
+
yield data, last_response
|
50
|
+
else
|
51
|
+
data[resource].concat(last_response[resource]) if data[resource].is_a?(Array)
|
52
|
+
data["meta"][resource].merge!(last_response["meta"][resource])
|
53
|
+
data["links"].merge!(last_response["links"])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
data
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def conn
|
63
|
+
@conn
|
64
|
+
end
|
65
|
+
|
66
|
+
def handle_response(response)
|
67
|
+
case response.status
|
68
|
+
when 404
|
69
|
+
raise ResourceNotFound, status: response.status, body: response.body
|
70
|
+
when 400..600
|
71
|
+
raise ServerError.new(response.body)
|
72
|
+
else
|
73
|
+
response.body
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "panoptes/concerns/common_client"
|
2
|
+
require "panoptes/client/discussions"
|
3
|
+
|
4
|
+
module Panoptes
|
5
|
+
class TalkClient
|
6
|
+
include Panoptes::CommonClient
|
7
|
+
include Panoptes::Client::Discussions
|
8
|
+
|
9
|
+
# @param auth [Hash] Authentication details
|
10
|
+
# * either nothing,
|
11
|
+
# * a hash with +:token+ (an existing OAuth user token),
|
12
|
+
# * or a hash with +:client_id+ and +:client_secret+ (a keypair for an OAuth Application).
|
13
|
+
# A client is the main interface to the talk v2 API.
|
14
|
+
# @param url [String] Optional override for the API location to use. Defaults to the official talk api production environment.
|
15
|
+
# @param auth_url [String] Optional override for the auth API location to use. Defaults to the official api production environment.
|
16
|
+
def initialize(auth: {}, url: PROD_TALK_API_URL, auth_url: PROD_API_URL)
|
17
|
+
super(auth: auth, url: url, auth_url: auth_url)
|
18
|
+
end
|
19
|
+
|
20
|
+
def get(path, query = {})
|
21
|
+
response = conn.get(path, query)
|
22
|
+
handle_response(response)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: panoptes-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marten Veldthuis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -114,6 +114,7 @@ files:
|
|
114
114
|
- bin/setup
|
115
115
|
- lib/panoptes-client.rb
|
116
116
|
- lib/panoptes/client.rb
|
117
|
+
- lib/panoptes/client/discussions.rb
|
117
118
|
- lib/panoptes/client/me.rb
|
118
119
|
- lib/panoptes/client/projects.rb
|
119
120
|
- lib/panoptes/client/subject_sets.rb
|
@@ -121,6 +122,8 @@ files:
|
|
121
122
|
- lib/panoptes/client/user_groups.rb
|
122
123
|
- lib/panoptes/client/version.rb
|
123
124
|
- lib/panoptes/client/workflows.rb
|
125
|
+
- lib/panoptes/concerns/common_client.rb
|
126
|
+
- lib/panoptes/talk_client.rb
|
124
127
|
- panoptes-client.gemspec
|
125
128
|
homepage: https://github.com/zooniverse/panoptes-client.rb
|
126
129
|
licenses:
|
@@ -142,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
145
|
version: '0'
|
143
146
|
requirements: []
|
144
147
|
rubyforge_project:
|
145
|
-
rubygems_version: 2.5.
|
148
|
+
rubygems_version: 2.5.1
|
146
149
|
signing_key:
|
147
150
|
specification_version: 4
|
148
151
|
summary: API wrapper for https://panoptes.zooniverse.org
|