solid-community-client-simple 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -2
- data/demo.rb +2 -2
- data/lib/{solid.rb → communityclient.rb} +62 -0
- data/lib/solid-community-client-simple.rb +1 -1
- data/lib/version.rb +0 -5
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f125d2c406da89148df7fd71ae7d5ba9e2a1ede71d62d33a67caae97abb4ffdd
|
4
|
+
data.tar.gz: acd26691bc2186a6fe7f7dd187b362233ff1bbd23794dfabd8dbf7bf9979d06c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5a707ba2188de4694b7d88f8b0ec1a5a6f3f7cc1cc0c0b871022ca4de8138b9f4dd73f518352b3e13a0346237ba9cef15259bb5a585cc11fa3bfaad97dd4d10
|
7
|
+
data.tar.gz: c7bf7a842b6a9fc24979ba37e25dfa04f8463ecd43d4df183635443328a33f97c8a3388ae6c876687eee0d516ead4df60832d14e4d94b0fe012823199c400f29
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# SOLID Client for Community Server
|
1
|
+
# SOLID Client for the SOLID Community Server
|
2
2
|
|
3
3
|
Talk to SOLID Pods
|
4
4
|
|
@@ -7,4 +7,28 @@ Talk to SOLID Pods
|
|
7
7
|
If you want an idea of what's happening behind the scenes, have a look at this Gist:
|
8
8
|
https://gist.github.com/markwilkinson/c5e819ae08d3753b1ee63edb2a504401
|
9
9
|
|
10
|
-
|
10
|
+
|
11
|
+
Note that this was created for a specific project, with a short timeline. It currently does only the things
|
12
|
+
I need it to do! It is not, in any way a full-featured SOLID POD library! Having said that, it does get you through all of the stages of login and to the point of having a DPOP proof that allows you to interact in an LDP-style manner with the POD (e.g. creating/updating/deleting Resources and/or Containers)
|
13
|
+
|
14
|
+
Future iterations will be much more powerful, as my requirements grow through the life of my project.
|
15
|
+
|
16
|
+
Example Interaction
|
17
|
+
|
18
|
+
```
|
19
|
+
# this assumes you are running the SOLID Community Client docker image exposing port 3000
|
20
|
+
# you must have already set-up a login and have a POD on that server to talk to!
|
21
|
+
|
22
|
+
require "solid-community-client-simple"
|
23
|
+
s = SOLID::CommunityClient.new(server: "http://localhost:3000/", username: "mark.wilkinson@upm.es", password: "markw")
|
24
|
+
s.login
|
25
|
+
at = s.get_current_access_token(webid: "http://localhost:3000/markw/profile/card#me", name: "codetest")
|
26
|
+
dpop = s.prepare_dpop(url: "http://localhost:3000/markw/", method: "get")
|
27
|
+
res = s.execute_with_proof(dpop: dpop, data: "", content_type: "text/turtle", current_access_token: at)
|
28
|
+
puts res.body
|
29
|
+
|
30
|
+
```
|
31
|
+
|
32
|
+
Please share bug reports via the Issues, but please also be aware that this is not (yet!) intended for widespread use. I simply found the documentation for interacting with the Community Server to be... extremely frustrating! (documentation should not be via software snippets!). Anyway, to avoid anyone else having to figure out what the javascript in that documentation is doing, I have captured it in this code, and in the Gist linked above.
|
33
|
+
|
34
|
+
Enjoy!
|
data/demo.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require "./lib/solid.rb"
|
2
|
-
|
1
|
+
# require "./lib/solid.rb"
|
2
|
+
require "solid-community-client-simple"
|
3
3
|
s = SOLID::CommunityClient.new(server: "http://localhost:3000/", username: "mark.wilkinson@upm.es", password: "markw")
|
4
4
|
s.login
|
5
5
|
at = s.get_current_access_token(webid: "http://localhost:3000/markw/profile/card#me", name: "codetest")
|
@@ -1,10 +1,22 @@
|
|
1
1
|
module SOLID
|
2
2
|
class CommunityClient
|
3
|
+
|
4
|
+
VERSION = "0.0.4"
|
5
|
+
|
3
6
|
require_relative './config'
|
4
7
|
|
5
8
|
attr_accessor :username, :password, :server, :account_meta, :login_meta, :credentials_url, :webid_url, :webids,
|
6
9
|
:css_account_token, :tokenid, :secret, :auth_string, :encoded_auth, :current_access_token
|
7
10
|
|
11
|
+
#
|
12
|
+
# Initialize the SOLID Community Client Object
|
13
|
+
#
|
14
|
+
# @param [String] server The URL of the SOLID Pod you want to interact with
|
15
|
+
# @param [String] username Your SOLID Pod username (defaults to ENV['SOLIDUSER'])
|
16
|
+
# @param [String] password Your SOLID Pod password (default to ENV['SOLIDPASSWORD'])
|
17
|
+
# @param [webid] webid Your WebID that you use for authentication against that POD (default nil)
|
18
|
+
#
|
19
|
+
# @return [SOLID::CommunityClient]
|
8
20
|
def initialize(server:, username: ENV['SOLIDUSER'], password: ENV['SOLIDPASSWORD'], webid: nil)
|
9
21
|
@username = username
|
10
22
|
@password = password
|
@@ -13,6 +25,17 @@ module SOLID
|
|
13
25
|
@webid = webid
|
14
26
|
end
|
15
27
|
|
28
|
+
#
|
29
|
+
# Login to the POD. This creates additional accessors in the SOLID::CommunityClient
|
30
|
+
# Including:
|
31
|
+
# #account_meta - this contains the parsed JSON from a GET on the PODs ./accout endpoint
|
32
|
+
# #login_meta - this contains the parsed JSON from a GET on the PODs login_url (part of the #account_meta)
|
33
|
+
# #credentials_url - the URL to be used to get credentials for the POD
|
34
|
+
# #webid_url - the URL to call to get the list of WebIDs that have access to this POD
|
35
|
+
#
|
36
|
+
#
|
37
|
+
# @return [Boolean] Was login successful? (if not, this method will crash, for the moment! No error tolerance at all!)
|
38
|
+
#
|
16
39
|
def login
|
17
40
|
account = server + '.account/'
|
18
41
|
|
@@ -56,6 +79,11 @@ module SOLID
|
|
56
79
|
true
|
57
80
|
end
|
58
81
|
|
82
|
+
#
|
83
|
+
# Retrieve the list of WebIDs that have access to this POD
|
84
|
+
#
|
85
|
+
# @return [Array[String]] an array of URL strings that are the webids of all legitimate POD users
|
86
|
+
#
|
59
87
|
def get_webids
|
60
88
|
resp = RestClient::Request.new({
|
61
89
|
method: :get,
|
@@ -71,6 +99,14 @@ module SOLID
|
|
71
99
|
webids
|
72
100
|
end
|
73
101
|
|
102
|
+
#
|
103
|
+
# Create the access token for this POD based in your WebID
|
104
|
+
#
|
105
|
+
# @param [String] webid The URL of your WebID
|
106
|
+
# @param [String] name some arbigtrary name to give your token (no sanity checking on the characters right now...)
|
107
|
+
#
|
108
|
+
# @return [String] The access token (this also sets the value of the SOLID::CommunityClient#current_access_token instance method)
|
109
|
+
#
|
74
110
|
def create_access_token(webid:, name: 'my-token')
|
75
111
|
payload = { "name": name, "webId": webid }.to_json
|
76
112
|
warn "", "", credentials_url, css_account_token, payload, "", ""
|
@@ -116,6 +152,14 @@ module SOLID
|
|
116
152
|
@current_access_token = j['access_token']
|
117
153
|
end
|
118
154
|
|
155
|
+
#
|
156
|
+
# Either retrieve or create a valid access token. This should be used in preference to create_access_token, because it has logic to test the validity of the current token, and renew if it has a remaining lifespan of less than 30 seconds.
|
157
|
+
#
|
158
|
+
# @param [String] webid Your WebID URL
|
159
|
+
# @param [String] name arbitrary string to call your token
|
160
|
+
#
|
161
|
+
# @return [String] The string of a valid token
|
162
|
+
#
|
119
163
|
def get_current_access_token(webid:, name: "my-token")
|
120
164
|
create_access_token(webid: webid, name: name) unless current_access_token && !(current_access_token.empty?)
|
121
165
|
|
@@ -141,11 +185,29 @@ module SOLID
|
|
141
185
|
current_access_token
|
142
186
|
end
|
143
187
|
|
188
|
+
#
|
189
|
+
# Get the CommunityClient ready to do a specific DPoP interaction. DPoP requires the URL that you will interact with, adn the HTEP method you will use. You have to call this method prior to every new kind of interaction with the POD
|
190
|
+
#
|
191
|
+
# @param [String] url The URL you will interact with
|
192
|
+
# @param [String] method The HTTP Method (e.g. GET)
|
193
|
+
#
|
194
|
+
# @return [SOLID::DPOP] a SOLID::DPOP object
|
195
|
+
#
|
144
196
|
def prepare_dpop(url:, method:)
|
145
197
|
SOLID::DPOP.new(url: url, method: method)
|
146
198
|
end
|
147
199
|
|
148
200
|
|
201
|
+
#
|
202
|
+
# Execute an interaction with a POD (e.g. read or create a resource or container)
|
203
|
+
#
|
204
|
+
# @param [SOLID::DPOP] dpop The appropriate DPOP object (created by #prepare_dpop)
|
205
|
+
# @param [String] data The data in your payload (can be "" but MUST be set, even for a GET!)
|
206
|
+
# @param [String] content_type the MIME Content-type for the data
|
207
|
+
# @param [String] current_access_token Your current access token (from #get_current_access_token)
|
208
|
+
#
|
209
|
+
# @return [RestClient::Response] This has no error checking at all... a failed request will cause a crash
|
210
|
+
#
|
149
211
|
def execute_with_proof(dpop:, data:, content_type:, current_access_token:)
|
150
212
|
|
151
213
|
req = RestClient::Request.new({
|
@@ -1 +1 @@
|
|
1
|
-
require_relative "./
|
1
|
+
require_relative "./communityclient.rb"
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solid-community-client-simple
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Wilkinson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A simple client to interact with the SOLID Community Server. NOTA BENE
|
14
14
|
- this is NOT a fully functional SOLID client. It does only what I need it to do
|
@@ -28,11 +28,11 @@ files:
|
|
28
28
|
- README.md
|
29
29
|
- demo.rb
|
30
30
|
- lib/account.rb
|
31
|
+
- lib/communityclient.rb
|
31
32
|
- lib/config.rb
|
32
33
|
- lib/dpop.rb
|
33
34
|
- lib/login.rb
|
34
35
|
- lib/solid-community-client-simple.rb
|
35
|
-
- lib/solid.rb
|
36
36
|
- lib/version.rb
|
37
37
|
- test.rb
|
38
38
|
homepage: https://github.com/markwilkinson/solid-community-client-simple
|
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
58
|
- !ruby/object:Gem::Version
|
59
59
|
version: '0'
|
60
60
|
requirements: []
|
61
|
-
rubygems_version: 3.
|
61
|
+
rubygems_version: 3.3.23
|
62
62
|
signing_key:
|
63
63
|
specification_version: 4
|
64
64
|
summary: A simple client to interact with the SOLID Community Server.
|