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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8719a30317bb3823939fbab9bbe3bd0437343e6d
4
- data.tar.gz: 64c12685ef64b9869d2ddf2bd52bd70f49f72540
3
+ metadata.gz: bc264446329a6b68234216a770d86e31b71475cd
4
+ data.tar.gz: 5cdefd445cbbeac411c6d81a31dba838455921e2
5
5
  SHA512:
6
- metadata.gz: 38f2430c3196e2016575a4e390f11240b0e0ab6caface54e3a3e31088fbb6baf93b8b4d11e970ce601be80a3e559e14edbddcce23d5f8988f4322fbf06d2d256
7
- data.tar.gz: a95d7ed28fb36acb6899a548fad064186855a398f96a8f91eb982755aa25e5219c6571f4264c3f0f47dc3c5a02fb35c873b8f215cc2a2e2a0cdc2f07eeb17612
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: 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
- # )
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
- 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
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
- puts "failed #{e}"
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: PoetFrostAPI.get_work(workId)
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
- puts "failed #{e}"
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
- puts "failed #{e}"
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.2
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/poet_frost_api.rb
19
+ - lib/poet_frost_API.rb
20
20
  homepage: https://github.com/minstrel/Poet-Frost-API-Wrapper
21
21
  licenses:
22
22
  - MIT