poet_frost_API 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/poet_frost_api.rb +72 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8719a30317bb3823939fbab9bbe3bd0437343e6d
|
4
|
+
data.tar.gz: 64c12685ef64b9869d2ddf2bd52bd70f49f72540
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 38f2430c3196e2016575a4e390f11240b0e0ab6caface54e3a3e31088fbb6baf93b8b4d11e970ce601be80a3e559e14edbddcce23d5f8988f4322fbf06d2d256
|
7
|
+
data.tar.gz: a95d7ed28fb36acb6899a548fad064186855a398f96a8f91eb982755aa25e5219c6571f4264c3f0f47dc3c5a02fb35c873b8f215cc2a2e2a0cdc2f07eeb17612
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
# To use any of the methods, register an API key at https://frost.po.et/
|
6
|
+
# and save it as the environment variable FROST_TOKEN.
|
7
|
+
module PoetFrostAPI
|
8
|
+
|
9
|
+
@@api_key = ENV['FROST_TOKEN']
|
10
|
+
@@uri = URI('https://api.frost.po.et/works/')
|
11
|
+
@@http = Net::HTTP.new(@@uri.host, @@uri.port)
|
12
|
+
@@http.use_ssl = true
|
13
|
+
|
14
|
+
# Register a work on Po.et.
|
15
|
+
#
|
16
|
+
# Usage: PoetFrostAPI.create_work(name: 'Work Name',
|
17
|
+
# datePublished: DateTime.now.iso8601,
|
18
|
+
# dateCreated: DateTime.now.iso8601,
|
19
|
+
# author: 'Author Name'
|
20
|
+
# tags: 'Tag1, Tag2'
|
21
|
+
# content: 'Content body'
|
22
|
+
# )
|
23
|
+
#
|
24
|
+
# Returns a string with the workid that was registered.
|
25
|
+
def PoetFrostAPI.create_work(args = {})
|
26
|
+
|
27
|
+
req = Net::HTTP::Post.new(@@uri.path)
|
28
|
+
req.content_type = 'application/json'
|
29
|
+
req['token'] = @@api_key
|
30
|
+
req.body = { name: args[:name],
|
31
|
+
datePublished: args[:datePublished] || DateTime.now.iso8601,
|
32
|
+
dateCreated: args[:dateCreated] || DateTime.now.iso8601,
|
33
|
+
author: args[:author],
|
34
|
+
tags: args[:tags] || '',
|
35
|
+
content: args[:content]
|
36
|
+
}.to_json
|
37
|
+
res = @@http.request(req)
|
38
|
+
JSON.parse(res.body)['workId']
|
39
|
+
rescue => e
|
40
|
+
puts "failed #{e}"
|
41
|
+
end
|
42
|
+
|
43
|
+
# Retrieve a specific work from Po.et, using the workId returned from
|
44
|
+
# create_work.
|
45
|
+
#
|
46
|
+
# Usage: PoetFrostAPI.get_work(workId)
|
47
|
+
#
|
48
|
+
# Returns a hash with the created fields.
|
49
|
+
def PoetFrostAPI.get_work(workId)
|
50
|
+
uri = @@uri + workId
|
51
|
+
req = Net::HTTP::Get.new(uri.path)
|
52
|
+
req.content_type = 'application/json'
|
53
|
+
req['token'] = @@api_key
|
54
|
+
res = @@http.request(req)
|
55
|
+
JSON.parse(res.body)
|
56
|
+
rescue => e
|
57
|
+
puts "failed #{e}"
|
58
|
+
end
|
59
|
+
|
60
|
+
# Retrieve all works submitted by your Frost API Token.
|
61
|
+
#
|
62
|
+
def PoetFrostAPI.get_all_works
|
63
|
+
req = Net::HTTP::Get.new(@@uri.path)
|
64
|
+
req.content_type = 'application/json'
|
65
|
+
req['token'] = @@api_key
|
66
|
+
res = @@http.request(req)
|
67
|
+
JSON.parse(res.body)
|
68
|
+
rescue => e
|
69
|
+
puts "failed #{e}"
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: poet_frost_API
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Donald Smith
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A Ruby wrapper for the Po.et Frost API
|
14
|
+
email: donald@sinbissquare.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/poet_frost_api.rb
|
20
|
+
homepage: https://github.com/minstrel/Poet-Frost-API-Wrapper
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.5.2.1
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: API Wrapper for Po.et Frost
|
44
|
+
test_files: []
|