solid-community-client-simple 0.0.2 → 0.0.3
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 +59 -0
- data/lib/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb57f2c8135d3faa45c2920c23b3524f7e9364bbdc3c16f423cab14fc19caa92
|
4
|
+
data.tar.gz: c4d848a43f8228153cd31af586e12795bf0592a40a9617f51b63e4aede39152f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b275de160f100f06f6bbf8b000521aa3ed767a1560498c7089a451ad9809ac8cd5e6eb1b0f15ae597bf16d695df9c070ddbd04a0a6ab322d41528890b3241e5
|
7
|
+
data.tar.gz: fea34b8719aa51866cd156f53444ef2dc32a419ad666ac507696844ec4e3a0cafe6477dd66188bf2948af03353b2241e30858dd599754cf21c8ffcfdca91ac42
|
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")
|
data/lib/solid.rb
CHANGED
@@ -5,6 +5,15 @@ module SOLID
|
|
5
5
|
attr_accessor :username, :password, :server, :account_meta, :login_meta, :credentials_url, :webid_url, :webids,
|
6
6
|
:css_account_token, :tokenid, :secret, :auth_string, :encoded_auth, :current_access_token
|
7
7
|
|
8
|
+
#
|
9
|
+
# Initialize the SOLID Community Client Object
|
10
|
+
#
|
11
|
+
# @param [String] server The URL of the SOLID Pod you want to interact with
|
12
|
+
# @param [String] username Your SOLID Pod username (defaults to ENV['SOLIDUSER'])
|
13
|
+
# @param [String] password Your SOLID Pod password (default to ENV['SOLIDPASSWORD'])
|
14
|
+
# @param [webid] webid Your WebID that you use for authentication against that POD (default nil)
|
15
|
+
#
|
16
|
+
# @return [SOLID::CommunityClient]
|
8
17
|
def initialize(server:, username: ENV['SOLIDUSER'], password: ENV['SOLIDPASSWORD'], webid: nil)
|
9
18
|
@username = username
|
10
19
|
@password = password
|
@@ -13,6 +22,17 @@ module SOLID
|
|
13
22
|
@webid = webid
|
14
23
|
end
|
15
24
|
|
25
|
+
#
|
26
|
+
# Login to the POD. This creates additional accessors in the SOLID::CommunityClient
|
27
|
+
# Including:
|
28
|
+
# #account_meta - this contains the parsed JSON from a GET on the PODs ./accout endpoint
|
29
|
+
# #login_meta - this contains the parsed JSON from a GET on the PODs login_url (part of the #account_meta)
|
30
|
+
# #credentials_url - the URL to be used to get credentials for the POD
|
31
|
+
# #webid_url - the URL to call to get the list of WebIDs that have access to this POD
|
32
|
+
#
|
33
|
+
#
|
34
|
+
# @return [Boolean] Was login successful? (if not, this method will crash, for the moment! No error tolerance at all!)
|
35
|
+
#
|
16
36
|
def login
|
17
37
|
account = server + '.account/'
|
18
38
|
|
@@ -56,6 +76,11 @@ module SOLID
|
|
56
76
|
true
|
57
77
|
end
|
58
78
|
|
79
|
+
#
|
80
|
+
# Retrieve the list of WebIDs that have access to this POD
|
81
|
+
#
|
82
|
+
# @return [Array[String]] an array of URL strings that are the webids of all legitimate POD users
|
83
|
+
#
|
59
84
|
def get_webids
|
60
85
|
resp = RestClient::Request.new({
|
61
86
|
method: :get,
|
@@ -71,6 +96,14 @@ module SOLID
|
|
71
96
|
webids
|
72
97
|
end
|
73
98
|
|
99
|
+
#
|
100
|
+
# Create the access token for this POD based in your WebID
|
101
|
+
#
|
102
|
+
# @param [String] webid The URL of your WebID
|
103
|
+
# @param [String] name some arbigtrary name to give your token (no sanity checking on the characters right now...)
|
104
|
+
#
|
105
|
+
# @return [String] The access token (this also sets the value of the SOLID::CommunityClient#current_access_token instance method)
|
106
|
+
#
|
74
107
|
def create_access_token(webid:, name: 'my-token')
|
75
108
|
payload = { "name": name, "webId": webid }.to_json
|
76
109
|
warn "", "", credentials_url, css_account_token, payload, "", ""
|
@@ -116,6 +149,14 @@ module SOLID
|
|
116
149
|
@current_access_token = j['access_token']
|
117
150
|
end
|
118
151
|
|
152
|
+
#
|
153
|
+
# 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.
|
154
|
+
#
|
155
|
+
# @param [String] webid Your WebID URL
|
156
|
+
# @param [String] name arbitrary string to call your token
|
157
|
+
#
|
158
|
+
# @return [String] The string of a valid token
|
159
|
+
#
|
119
160
|
def get_current_access_token(webid:, name: "my-token")
|
120
161
|
create_access_token(webid: webid, name: name) unless current_access_token && !(current_access_token.empty?)
|
121
162
|
|
@@ -141,11 +182,29 @@ module SOLID
|
|
141
182
|
current_access_token
|
142
183
|
end
|
143
184
|
|
185
|
+
#
|
186
|
+
# 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
|
187
|
+
#
|
188
|
+
# @param [String] url The URL you will interact with
|
189
|
+
# @param [String] method The HTTP Method (e.g. GET)
|
190
|
+
#
|
191
|
+
# @return [SOLID::DPOP] a SOLID::DPOP object
|
192
|
+
#
|
144
193
|
def prepare_dpop(url:, method:)
|
145
194
|
SOLID::DPOP.new(url: url, method: method)
|
146
195
|
end
|
147
196
|
|
148
197
|
|
198
|
+
#
|
199
|
+
# Execute an interaction with a POD (e.g. read or create a resource or container)
|
200
|
+
#
|
201
|
+
# @param [SOLID::DPOP] dpop The appropriate DPOP object (created by #prepare_dpop)
|
202
|
+
# @param [String] data The data in your payload (can be "" but MUST be set, even for a GET!)
|
203
|
+
# @param [String] content_type the MIME Content-type for the data
|
204
|
+
# @param [String] current_access_token Your current access token (from #get_current_access_token)
|
205
|
+
#
|
206
|
+
# @return [RestClient::Response] This has no error checking at all... a failed request will cause a crash
|
207
|
+
#
|
149
208
|
def execute_with_proof(dpop:, data:, content_type:, current_access_token:)
|
150
209
|
|
151
210
|
req = RestClient::Request.new({
|
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.3
|
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
|
@@ -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.
|