poet_frost_API 0.0.2 → 0.0.4
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/lib/{poet_frost_api.rb → poet_frost_API.rb} +32 -18
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc264446329a6b68234216a770d86e31b71475cd
|
4
|
+
data.tar.gz: 5cdefd445cbbeac411c6d81a31dba838455921e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 594995c675c54b5724a45c17ec5b4d3d2fab931a3bf21d76f0e0d78c9058a69237f5c9212686a8c11927395cc6ca27547b41faccceaaf7bc57cf7745c8db1213
|
7
|
+
data.tar.gz: 3a4e6703bc4bcf176a4a3200143b1e995e82ef34c55ebb0efdf89aea03d6c23ba29b36fcb97f916a175abf28c6b410a1876205a6dc3317a36da65ef572f5ed29
|
@@ -4,6 +4,8 @@ require 'date'
|
|
4
4
|
|
5
5
|
# To use any of the methods, register an API key at https://frost.po.et/
|
6
6
|
# and save it as the environment variable FROST_TOKEN.
|
7
|
+
# For the current easiest way to integrate to Rails, see the github readme
|
8
|
+
# here: https://github.com/minstrel/Poet-Frost-API-Wrapper
|
7
9
|
module PoetFrostAPI
|
8
10
|
|
9
11
|
@@api_key = ENV['FROST_TOKEN']
|
@@ -13,13 +15,17 @@ module PoetFrostAPI
|
|
13
15
|
|
14
16
|
# Register a work on Po.et.
|
15
17
|
#
|
16
|
-
# Usage:
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
18
|
+
# Usage:
|
19
|
+
# PoetFrostAPI.create_work(name: 'Work Name',
|
20
|
+
# datePublished: DateTime.now.iso8601,
|
21
|
+
# dateCreated: DateTime.now.iso8601,
|
22
|
+
# author: 'Author Name'
|
23
|
+
# tags: 'Tag1, Tag2'
|
24
|
+
# content: 'Content body'
|
25
|
+
# )
|
26
|
+
#
|
27
|
+
# datePublished and dateCreated will default to current datetime if omitted
|
28
|
+
# tags will default to blank string if omitted
|
23
29
|
#
|
24
30
|
# Returns a string with the workid that was registered.
|
25
31
|
def PoetFrostAPI.create_work(args = {})
|
@@ -27,23 +33,27 @@ module PoetFrostAPI
|
|
27
33
|
req = Net::HTTP::Post.new(@@uri.path)
|
28
34
|
req.content_type = 'application/json'
|
29
35
|
req['token'] = @@api_key
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
36
|
+
args.keep_if { |k, v| [:name,
|
37
|
+
:datePublished,
|
38
|
+
:dateCreated,
|
39
|
+
:author,
|
40
|
+
:tags,
|
41
|
+
:content].include?(k) }
|
42
|
+
args[:datePublished] ||= DateTime.now.iso8601
|
43
|
+
args[:dateCreated] ||= DateTime.now.iso8601
|
44
|
+
args[:tags] ||= ''
|
45
|
+
req.body = args.to_json
|
37
46
|
res = @@http.request(req)
|
38
47
|
JSON.parse(res.body)['workId']
|
39
48
|
rescue => e
|
40
|
-
|
49
|
+
"failed #{e}"
|
41
50
|
end
|
42
51
|
|
43
52
|
# Retrieve a specific work from Po.et, using the workId returned from
|
44
53
|
# create_work.
|
45
54
|
#
|
46
|
-
# Usage:
|
55
|
+
# Usage:
|
56
|
+
# PoetFrostAPI.get_work(workId)
|
47
57
|
#
|
48
58
|
# Returns a hash with the created fields.
|
49
59
|
def PoetFrostAPI.get_work(workId)
|
@@ -54,11 +64,15 @@ module PoetFrostAPI
|
|
54
64
|
res = @@http.request(req)
|
55
65
|
JSON.parse(res.body)
|
56
66
|
rescue => e
|
57
|
-
|
67
|
+
"failed #{e}"
|
58
68
|
end
|
59
69
|
|
60
70
|
# Retrieve all works submitted by your Frost API Token.
|
61
71
|
#
|
72
|
+
# Usage:
|
73
|
+
# PoetFrostAPI.get_all_works
|
74
|
+
#
|
75
|
+
# Returns an array of individual works (hashes)
|
62
76
|
def PoetFrostAPI.get_all_works
|
63
77
|
req = Net::HTTP::Get.new(@@uri.path)
|
64
78
|
req.content_type = 'application/json'
|
@@ -66,7 +80,7 @@ module PoetFrostAPI
|
|
66
80
|
res = @@http.request(req)
|
67
81
|
JSON.parse(res.body)
|
68
82
|
rescue => e
|
69
|
-
|
83
|
+
"failed #{e}"
|
70
84
|
end
|
71
85
|
|
72
86
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: poet_frost_API
|
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
|
- Donald Smith
|
@@ -16,7 +16,7 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
-
- lib/
|
19
|
+
- lib/poet_frost_API.rb
|
20
20
|
homepage: https://github.com/minstrel/Poet-Frost-API-Wrapper
|
21
21
|
licenses:
|
22
22
|
- MIT
|