thumbtack 1.1.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/thumbtack.rb +3 -3
- data/lib/thumbtack/adapters/basic_adapter.rb +31 -6
- data/lib/thumbtack/client.rb +3 -2
- data/lib/thumbtack/hash_to_digest.rb +5 -4
- data/lib/thumbtack/note.rb +15 -15
- data/lib/thumbtack/note_summary.rb +14 -14
- data/lib/thumbtack/notes.rb +1 -1
- data/lib/thumbtack/post.rb +14 -14
- data/lib/thumbtack/posts.rb +11 -11
- data/lib/thumbtack/specification.rb +1 -1
- data/lib/thumbtack/suggestion.rb +3 -3
- data/lib/thumbtack/symbolize_keys.rb +1 -1
- data/lib/thumbtack/tags.rb +1 -1
- data/lib/thumbtack/types/boolean.rb +2 -2
- data/lib/thumbtack/types/date.rb +1 -1
- data/lib/thumbtack/types/identity.rb +1 -1
- data/lib/thumbtack/types/integer.rb +1 -1
- data/lib/thumbtack/types/length_validation.rb +3 -3
- data/lib/thumbtack/types/md5.rb +4 -4
- data/lib/thumbtack/types/range_validation.rb +3 -3
- data/lib/thumbtack/types/tags.rb +7 -7
- data/lib/thumbtack/types/text.rb +1 -1
- data/lib/thumbtack/types/{date_time.rb → time.rb} +13 -13
- data/lib/thumbtack/types/title.rb +1 -1
- data/lib/thumbtack/types/url.rb +4 -4
- data/lib/thumbtack/user.rb +1 -1
- data/lib/thumbtack/version.rb +2 -2
- data/test/test_helper.rb +7 -4
- data/test/thumbtack/client_test.rb +1 -1
- data/test/thumbtack/integration/basic_adapter_test.rb +2 -2
- data/test/thumbtack/note_summary_test.rb +3 -3
- data/test/thumbtack/note_test.rb +3 -3
- data/test/thumbtack/notes_test.rb +1 -1
- data/test/thumbtack/post_test.rb +3 -3
- data/test/thumbtack/posts_test.rb +24 -46
- data/test/thumbtack/specification_test.rb +3 -2
- data/test/thumbtack/suggestion_test.rb +5 -5
- data/test/thumbtack/tags_test.rb +1 -9
- data/test/thumbtack/types/boolean_test.rb +1 -1
- data/test/thumbtack/types/date_test.rb +1 -1
- data/test/thumbtack/types/identity_test.rb +1 -1
- data/test/thumbtack/types/integer_test.rb +1 -1
- data/test/thumbtack/types/md5_test.rb +1 -1
- data/test/thumbtack/types/tags_test.rb +3 -3
- data/test/thumbtack/types/text_test.rb +1 -1
- data/test/thumbtack/types/time_test.rb +32 -0
- data/test/thumbtack/types/title_test.rb +1 -1
- data/test/thumbtack/types/url_test.rb +1 -1
- data/test/thumbtack/user_test.rb +1 -1
- metadata +37 -39
- data/test/thumbtack/types/date_time_test.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fdeb8a886aee18bb6a5bebb004f07d96b8cca96e84169de995f115cc5ffdf933
|
4
|
+
data.tar.gz: 05a649480964bb21531aa85c47e6c0fd0b87707ef810961a92447982fec28bc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39c4e82c954f3ea963582a0e8518b3b1c15b96ede42cd02e0a8aae535a65bfbc5c5183e0218a41aebd49667b399952e946d7bb06b98a4a2ba4e34b3f76f94d0f
|
7
|
+
data.tar.gz: 94c148bf9e8697116a442504e2b16965bf4a7163876d0f62ffd6031e36a07cb446073977feb478958eab2eb8979737c07bbcf43b296f911073fa2e4fba47a0b2
|
data/lib/thumbtack.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# A simple Pinboard API wrapper
|
4
4
|
module Thumbtack
|
@@ -20,21 +20,21 @@ module Thumbtack
|
|
20
20
|
EMPTY_ARRAY = [].freeze
|
21
21
|
end
|
22
22
|
|
23
|
-
require 'date'
|
24
23
|
require 'json'
|
25
24
|
require 'net/http'
|
25
|
+
require 'time'
|
26
26
|
require 'uri'
|
27
27
|
|
28
28
|
require 'thumbtack/types/range_validation'
|
29
29
|
require 'thumbtack/types/length_validation'
|
30
30
|
require 'thumbtack/types/boolean'
|
31
31
|
require 'thumbtack/types/date'
|
32
|
-
require 'thumbtack/types/date_time'
|
33
32
|
require 'thumbtack/types/identity'
|
34
33
|
require 'thumbtack/types/integer'
|
35
34
|
require 'thumbtack/types/md5'
|
36
35
|
require 'thumbtack/types/tags'
|
37
36
|
require 'thumbtack/types/text'
|
37
|
+
require 'thumbtack/types/time'
|
38
38
|
require 'thumbtack/types/title'
|
39
39
|
require 'thumbtack/types/url'
|
40
40
|
require 'thumbtack/specification'
|
@@ -1,17 +1,23 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thumbtack
|
4
4
|
module Adapters
|
5
5
|
# A basic adapter using Ruby's builtin HTTP and JSON parsing libraries
|
6
6
|
class BasicAdapter
|
7
7
|
# The status code for rate limited responses from the Pinboard API
|
8
|
-
TOO_MANY_REQUESTS_CODE = '429'
|
8
|
+
TOO_MANY_REQUESTS_CODE = '429'
|
9
9
|
|
10
10
|
# The response format requested from the Pinboard API
|
11
|
-
RESPONSE_FORMAT = 'json'
|
11
|
+
RESPONSE_FORMAT = 'json'
|
12
12
|
|
13
13
|
# The base Pinboard API URL.
|
14
|
-
BASE_URL = 'https://api.pinboard.in/v1'
|
14
|
+
BASE_URL = 'https://api.pinboard.in/v1'
|
15
|
+
|
16
|
+
# A secure version of SSL
|
17
|
+
SSL_VERSION = 'TLSv1_2'
|
18
|
+
|
19
|
+
# Secure cipher list
|
20
|
+
SSL_CIPHERS = 'TLSv1.2:!aNULL:!eNULL'
|
15
21
|
|
16
22
|
# Initialize a BasicAdapter
|
17
23
|
#
|
@@ -60,8 +66,27 @@ module Thumbtack
|
|
60
66
|
# @api private
|
61
67
|
# @raise [RateLimitError] if the response is rate-limited
|
62
68
|
def http_response(uri)
|
63
|
-
Net::HTTP.
|
64
|
-
|
69
|
+
request = Net::HTTP::Get.new(uri)
|
70
|
+
connection(uri.host, uri.port).request(request).tap do |response|
|
71
|
+
raise RateLimitError if response.code == TOO_MANY_REQUESTS_CODE
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Construct a secure HTTP connection to the Pinboard API
|
76
|
+
#
|
77
|
+
# @param [String] host
|
78
|
+
# the Pinboard API host
|
79
|
+
# @param [Fixnum] port
|
80
|
+
# the Pinboard API port
|
81
|
+
# @return [Net::HTTP]
|
82
|
+
# the connection
|
83
|
+
#
|
84
|
+
# @api private
|
85
|
+
def connection(host, port)
|
86
|
+
Net::HTTP.new(host, port).tap do |connection|
|
87
|
+
connection.use_ssl = true
|
88
|
+
connection.ssl_version = SSL_VERSION
|
89
|
+
connection.ciphers = SSL_CIPHERS
|
65
90
|
end
|
66
91
|
end
|
67
92
|
|
data/lib/thumbtack/client.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thumbtack
|
4
4
|
# Wraps each interaction with the Pinboard API
|
@@ -91,8 +91,9 @@ module Thumbtack
|
|
91
91
|
def action(path, params)
|
92
92
|
response = @adapter.get(path, params)
|
93
93
|
unless response['result_code'] == 'done'
|
94
|
-
|
94
|
+
raise ResultError, response['result_code']
|
95
95
|
end
|
96
|
+
|
96
97
|
self
|
97
98
|
end
|
98
99
|
|
@@ -1,12 +1,13 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thumbtack
|
4
|
-
# Handles renaming the hash attribute to digest from response hashes.
|
4
|
+
# Handles renaming the hash attribute to digest from response hashes. This is
|
5
|
+
# required in order to avoid collisions with the `Object#hash` method.
|
5
6
|
#
|
6
7
|
# @api private
|
7
8
|
class HashToDigest
|
8
|
-
HASH = 'hash'
|
9
|
-
DIGEST = 'digest'
|
9
|
+
HASH = 'hash'
|
10
|
+
DIGEST = 'digest'
|
10
11
|
|
11
12
|
# Rename any attribute called hash to digest
|
12
13
|
#
|
data/lib/thumbtack/note.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thumbtack
|
4
4
|
# Represents a note
|
@@ -8,14 +8,14 @@ module Thumbtack
|
|
8
8
|
# The attributes for a Note
|
9
9
|
#
|
10
10
|
# @api private
|
11
|
-
ATTRIBUTES = [
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
ATTRIBUTES = %i[
|
12
|
+
id
|
13
|
+
title
|
14
|
+
created_at
|
15
|
+
updated_at
|
16
|
+
digest
|
17
|
+
text
|
18
|
+
length
|
19
19
|
].freeze
|
20
20
|
|
21
21
|
# The identifier for the note
|
@@ -41,25 +41,25 @@ module Thumbtack
|
|
41
41
|
# The time at which the note was created
|
42
42
|
#
|
43
43
|
# @example
|
44
|
-
# note.created_at # =>
|
44
|
+
# note.created_at # => 2014-08-13 19:53:16 +0000
|
45
45
|
#
|
46
|
-
# @return [
|
46
|
+
# @return [Time]
|
47
47
|
#
|
48
48
|
# @api public
|
49
49
|
def created_at
|
50
|
-
Types::
|
50
|
+
Types::Time.deserialize_from_note(@created_at)
|
51
51
|
end
|
52
52
|
|
53
53
|
# The time at which the note was last updated
|
54
54
|
#
|
55
55
|
# @example
|
56
|
-
# note.updated_at # =>
|
56
|
+
# note.updated_at # => 2014-08-13 19:53:16 +0000
|
57
57
|
#
|
58
|
-
# @return [
|
58
|
+
# @return [Time]
|
59
59
|
#
|
60
60
|
# @api public
|
61
61
|
def updated_at
|
62
|
-
Types::
|
62
|
+
Types::Time.deserialize_from_note(@updated_at)
|
63
63
|
end
|
64
64
|
|
65
65
|
# 20 character hexadecimal SHA1 hash of the note text
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thumbtack
|
4
4
|
# Represents a note summary as returned from Notes#list.
|
@@ -9,13 +9,13 @@ module Thumbtack
|
|
9
9
|
# The attributes for a NoteSummary
|
10
10
|
#
|
11
11
|
# @api private
|
12
|
-
ATTRIBUTES = [
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
ATTRIBUTES = %i[
|
13
|
+
id
|
14
|
+
title
|
15
|
+
digest
|
16
|
+
created_at
|
17
|
+
updated_at
|
18
|
+
length
|
19
19
|
].freeze
|
20
20
|
|
21
21
|
# The identifier for the note
|
@@ -41,25 +41,25 @@ module Thumbtack
|
|
41
41
|
# The time at which the note was created
|
42
42
|
#
|
43
43
|
# @example
|
44
|
-
# note.created_at # =>
|
44
|
+
# note.created_at # => 2014-08-13 19:53:16 +0000
|
45
45
|
#
|
46
|
-
# @return [
|
46
|
+
# @return [Time]
|
47
47
|
#
|
48
48
|
# @api public
|
49
49
|
def created_at
|
50
|
-
Types::
|
50
|
+
Types::Time.deserialize_from_note(@created_at)
|
51
51
|
end
|
52
52
|
|
53
53
|
# The time at which the note was last updated
|
54
54
|
#
|
55
55
|
# @example
|
56
|
-
# note.updated_at # =>
|
56
|
+
# note.updated_at # => 2014-08-13 19:53:16 +0000
|
57
57
|
#
|
58
|
-
# @return [
|
58
|
+
# @return [Time]
|
59
59
|
#
|
60
60
|
# @api public
|
61
61
|
def updated_at
|
62
|
-
Types::
|
62
|
+
Types::Time.deserialize_from_note(@updated_at)
|
63
63
|
end
|
64
64
|
|
65
65
|
# 20 character hexadecimal SHA1 hash of the note text
|
data/lib/thumbtack/notes.rb
CHANGED
data/lib/thumbtack/post.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thumbtack
|
4
4
|
# Represents a bookmark
|
@@ -8,16 +8,16 @@ module Thumbtack
|
|
8
8
|
# The attributes for a Post
|
9
9
|
#
|
10
10
|
# @api private
|
11
|
-
ATTRIBUTES = [
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
11
|
+
ATTRIBUTES = %i[
|
12
|
+
href
|
13
|
+
description
|
14
|
+
extended
|
15
|
+
meta
|
16
|
+
digest
|
17
|
+
time
|
18
|
+
shared
|
19
|
+
toread
|
20
|
+
tags
|
21
21
|
].freeze
|
22
22
|
|
23
23
|
# The url of the post
|
@@ -73,13 +73,13 @@ module Thumbtack
|
|
73
73
|
# The time at which the post was created
|
74
74
|
#
|
75
75
|
# @example
|
76
|
-
# post.time # =>
|
76
|
+
# post.time # => 2014-08-13 19:53:16 +0000
|
77
77
|
#
|
78
|
-
# @return [
|
78
|
+
# @return [Time]
|
79
79
|
#
|
80
80
|
# @api public
|
81
81
|
def time
|
82
|
-
Types::
|
82
|
+
Types::Time.deserialize(@time)
|
83
83
|
end
|
84
84
|
|
85
85
|
# If true, this post is public
|
data/lib/thumbtack/posts.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thumbtack
|
4
4
|
# Wraps API calls related to posts
|
@@ -18,14 +18,14 @@ module Thumbtack
|
|
18
18
|
# @example
|
19
19
|
# update_time = posts.update
|
20
20
|
#
|
21
|
-
# @return [
|
21
|
+
# @return [Time]
|
22
22
|
#
|
23
23
|
# @api public
|
24
24
|
#
|
25
25
|
# @see https://pinboard.in/api/#posts_update
|
26
26
|
def update
|
27
27
|
response = @client.get('/posts/update')
|
28
|
-
Types::
|
28
|
+
Types::Time.deserialize response.fetch('update_time')
|
29
29
|
end
|
30
30
|
|
31
31
|
# Add a bookmark
|
@@ -43,7 +43,7 @@ module Thumbtack
|
|
43
43
|
# a description of the bookmark
|
44
44
|
# @option options [Array[String]] :tags
|
45
45
|
# a list of up to 100 tags
|
46
|
-
# @option options [
|
46
|
+
# @option options [Time] :dt
|
47
47
|
# the creation time for this bookmark
|
48
48
|
# @option options [Boolean] :replace
|
49
49
|
# if true, replace any existing bookmark with the same URL
|
@@ -63,7 +63,7 @@ module Thumbtack
|
|
63
63
|
description: Types::Text,
|
64
64
|
extended: Types::Text,
|
65
65
|
tags: Types::Tags,
|
66
|
-
dt: Types::
|
66
|
+
dt: Types::Time,
|
67
67
|
replace: Types::Boolean,
|
68
68
|
shared: Types::Boolean,
|
69
69
|
toread: Types::Boolean
|
@@ -100,7 +100,7 @@ module Thumbtack
|
|
100
100
|
# options to filter the results by
|
101
101
|
# @option options [Array<String>] :tag
|
102
102
|
# up to three tags to filter by
|
103
|
-
# @option options [
|
103
|
+
# @option options [Time] :dt
|
104
104
|
# which day the results were bookmarked
|
105
105
|
# @option options [String] :url
|
106
106
|
# the URL for this bookmark
|
@@ -115,7 +115,7 @@ module Thumbtack
|
|
115
115
|
def get(options = EMPTY_HASH)
|
116
116
|
parameters = Specification.new(
|
117
117
|
tag: Types::Tags,
|
118
|
-
dt: Types::
|
118
|
+
dt: Types::Time,
|
119
119
|
url: Types::URL,
|
120
120
|
meta: Types::Boolean
|
121
121
|
).parameters(options)
|
@@ -160,9 +160,9 @@ module Thumbtack
|
|
160
160
|
# an offset value
|
161
161
|
# @option options [Array<String>] :results
|
162
162
|
# number of results to return
|
163
|
-
# @option options [
|
163
|
+
# @option options [Time] :fromdt
|
164
164
|
# limit results to those created after this time
|
165
|
-
# @option options [
|
165
|
+
# @option options [Time] :todt
|
166
166
|
# limit results to those created before this time
|
167
167
|
# @option options [Boolean] :meta
|
168
168
|
# if true, include the change detection signature in the results
|
@@ -177,8 +177,8 @@ module Thumbtack
|
|
177
177
|
tag: Types::Tags,
|
178
178
|
start: Types::Integer,
|
179
179
|
results: Types::Integer,
|
180
|
-
fromdt: Types::
|
181
|
-
todt: Types::
|
180
|
+
fromdt: Types::Time,
|
181
|
+
todt: Types::Time,
|
182
182
|
meta: Types::Boolean
|
183
183
|
).parameters(options)
|
184
184
|
results = @client.get('/posts/all', parameters)
|
data/lib/thumbtack/suggestion.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thumbtack
|
4
4
|
# Represents a suggestion
|
@@ -8,12 +8,12 @@ module Thumbtack
|
|
8
8
|
# The key associated with popular tags
|
9
9
|
#
|
10
10
|
# @api private
|
11
|
-
POPULAR_KEY = 'popular'
|
11
|
+
POPULAR_KEY = 'popular'
|
12
12
|
|
13
13
|
# The key associated with suggested tags
|
14
14
|
#
|
15
15
|
# @api private
|
16
|
-
RECOMMENDED_KEY = 'recommended'
|
16
|
+
RECOMMENDED_KEY = 'recommended'
|
17
17
|
|
18
18
|
# A list of popular tags for URL
|
19
19
|
#
|
data/lib/thumbtack/tags.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thumbtack
|
4
4
|
module Types
|
@@ -21,7 +21,7 @@ module Thumbtack
|
|
21
21
|
when TrueClass, FalseClass
|
22
22
|
self
|
23
23
|
else
|
24
|
-
|
24
|
+
raise ValidationError, "#{value} must be true or false"
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|