thumbtack 1.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +5 -5
  2. data/lib/thumbtack.rb +3 -3
  3. data/lib/thumbtack/adapters/basic_adapter.rb +31 -6
  4. data/lib/thumbtack/client.rb +3 -2
  5. data/lib/thumbtack/hash_to_digest.rb +5 -4
  6. data/lib/thumbtack/note.rb +15 -15
  7. data/lib/thumbtack/note_summary.rb +14 -14
  8. data/lib/thumbtack/notes.rb +1 -1
  9. data/lib/thumbtack/post.rb +14 -14
  10. data/lib/thumbtack/posts.rb +11 -11
  11. data/lib/thumbtack/specification.rb +1 -1
  12. data/lib/thumbtack/suggestion.rb +3 -3
  13. data/lib/thumbtack/symbolize_keys.rb +1 -1
  14. data/lib/thumbtack/tags.rb +1 -1
  15. data/lib/thumbtack/types/boolean.rb +2 -2
  16. data/lib/thumbtack/types/date.rb +1 -1
  17. data/lib/thumbtack/types/identity.rb +1 -1
  18. data/lib/thumbtack/types/integer.rb +1 -1
  19. data/lib/thumbtack/types/length_validation.rb +3 -3
  20. data/lib/thumbtack/types/md5.rb +4 -4
  21. data/lib/thumbtack/types/range_validation.rb +3 -3
  22. data/lib/thumbtack/types/tags.rb +7 -7
  23. data/lib/thumbtack/types/text.rb +1 -1
  24. data/lib/thumbtack/types/{date_time.rb → time.rb} +13 -13
  25. data/lib/thumbtack/types/title.rb +1 -1
  26. data/lib/thumbtack/types/url.rb +4 -4
  27. data/lib/thumbtack/user.rb +1 -1
  28. data/lib/thumbtack/version.rb +2 -2
  29. data/test/test_helper.rb +7 -4
  30. data/test/thumbtack/client_test.rb +1 -1
  31. data/test/thumbtack/integration/basic_adapter_test.rb +2 -2
  32. data/test/thumbtack/note_summary_test.rb +3 -3
  33. data/test/thumbtack/note_test.rb +3 -3
  34. data/test/thumbtack/notes_test.rb +1 -1
  35. data/test/thumbtack/post_test.rb +3 -3
  36. data/test/thumbtack/posts_test.rb +24 -46
  37. data/test/thumbtack/specification_test.rb +3 -2
  38. data/test/thumbtack/suggestion_test.rb +5 -5
  39. data/test/thumbtack/tags_test.rb +1 -9
  40. data/test/thumbtack/types/boolean_test.rb +1 -1
  41. data/test/thumbtack/types/date_test.rb +1 -1
  42. data/test/thumbtack/types/identity_test.rb +1 -1
  43. data/test/thumbtack/types/integer_test.rb +1 -1
  44. data/test/thumbtack/types/md5_test.rb +1 -1
  45. data/test/thumbtack/types/tags_test.rb +3 -3
  46. data/test/thumbtack/types/text_test.rb +1 -1
  47. data/test/thumbtack/types/time_test.rb +32 -0
  48. data/test/thumbtack/types/title_test.rb +1 -1
  49. data/test/thumbtack/types/url_test.rb +1 -1
  50. data/test/thumbtack/user_test.rb +1 -1
  51. metadata +37 -39
  52. data/test/thumbtack/types/date_time_test.rb +0 -33
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 865dedec8bc24d93f1134a1a4b0515decd1ab4cb
4
- data.tar.gz: 55d72d32a1a29eeee1578fb3736ba20f643f721d
2
+ SHA256:
3
+ metadata.gz: fdeb8a886aee18bb6a5bebb004f07d96b8cca96e84169de995f115cc5ffdf933
4
+ data.tar.gz: 05a649480964bb21531aa85c47e6c0fd0b87707ef810961a92447982fec28bc0
5
5
  SHA512:
6
- metadata.gz: 5eb64b30a1a0f11dc500e9e48017467f807026e6526278c046602424a65fdc1bbd419f634a46323b86994181d6d80de59fe91f67312f9717695bb1c12ce0288d
7
- data.tar.gz: 4d9462b77cfe56905794db3e876c93bd20a487a4ed5d510de210f37c714a5efeea55c60bd12eb5fe6b1f75ca787075262965ca8afc4d6dd2c95d9dfcb27cfb63
6
+ metadata.gz: 39c4e82c954f3ea963582a0e8518b3b1c15b96ede42cd02e0a8aae535a65bfbc5c5183e0218a41aebd49667b399952e946d7bb06b98a4a2ba4e34b3f76f94d0f
7
+ data.tar.gz: 94c148bf9e8697116a442504e2b16965bf4a7163876d0f62ffd6031e36a07cb446073977feb478958eab2eb8979737c07bbcf43b296f911073fa2e4fba47a0b2
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
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
- # encoding: utf-8
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'.freeze
8
+ TOO_MANY_REQUESTS_CODE = '429'
9
9
 
10
10
  # The response format requested from the Pinboard API
11
- RESPONSE_FORMAT = 'json'.freeze
11
+ RESPONSE_FORMAT = 'json'
12
12
 
13
13
  # The base Pinboard API URL.
14
- BASE_URL = 'https://api.pinboard.in/v1'.freeze
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.get_response(uri).tap do |response|
64
- fail RateLimitError if response.code == TOO_MANY_REQUESTS_CODE
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
 
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
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
- fail ResultError, response['result_code']
94
+ raise ResultError, response['result_code']
95
95
  end
96
+
96
97
  self
97
98
  end
98
99
 
@@ -1,12 +1,13 @@
1
- # encoding: utf-8
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'.freeze
9
- DIGEST = 'digest'.freeze
9
+ HASH = 'hash'
10
+ DIGEST = 'digest'
10
11
 
11
12
  # Rename any attribute called hash to digest
12
13
  #
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
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
- :id,
13
- :title,
14
- :created_at,
15
- :updated_at,
16
- :digest,
17
- :text,
18
- :length
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 # => #<DateTime: 2014-08-13T19:53:16+00:00...
44
+ # note.created_at # => 2014-08-13 19:53:16 +0000
45
45
  #
46
- # @return [DateTime]
46
+ # @return [Time]
47
47
  #
48
48
  # @api public
49
49
  def created_at
50
- Types::DateTime.deserialize_from_note(@created_at)
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 # => #<DateTime: 2014-08-13T19:53:16+00:00...
56
+ # note.updated_at # => 2014-08-13 19:53:16 +0000
57
57
  #
58
- # @return [DateTime]
58
+ # @return [Time]
59
59
  #
60
60
  # @api public
61
61
  def updated_at
62
- Types::DateTime.deserialize_from_note(@updated_at)
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
- # encoding: utf-8
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
- :id,
14
- :title,
15
- :digest,
16
- :created_at,
17
- :updated_at,
18
- :length
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 # => #<DateTime: 2014-08-13T19:53:16+00:00...
44
+ # note.created_at # => 2014-08-13 19:53:16 +0000
45
45
  #
46
- # @return [DateTime]
46
+ # @return [Time]
47
47
  #
48
48
  # @api public
49
49
  def created_at
50
- Types::DateTime.deserialize_from_note(@created_at)
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 # => #<DateTime: 2014-08-13T19:53:16+00:00...
56
+ # note.updated_at # => 2014-08-13 19:53:16 +0000
57
57
  #
58
- # @return [DateTime]
58
+ # @return [Time]
59
59
  #
60
60
  # @api public
61
61
  def updated_at
62
- Types::DateTime.deserialize_from_note(@updated_at)
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
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Thumbtack
4
4
  # Wraps API calls related to notes
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
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
- :href,
13
- :description,
14
- :extended,
15
- :meta,
16
- :digest,
17
- :time,
18
- :shared,
19
- :toread,
20
- :tags
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 # => #<DateTime: 2014-09-17T13:45:27+00:00...
76
+ # post.time # => 2014-08-13 19:53:16 +0000
77
77
  #
78
- # @return [DateTime]
78
+ # @return [Time]
79
79
  #
80
80
  # @api public
81
81
  def time
82
- Types::DateTime.deserialize(@time)
82
+ Types::Time.deserialize(@time)
83
83
  end
84
84
 
85
85
  # If true, this post is public
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
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 [DateTime]
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::DateTime.deserialize response.fetch('update_time')
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 [DateTime] :dt
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::DateTime,
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 [DateTime] :dt
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::DateTime,
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 [DateTime] :fromdt
163
+ # @option options [Time] :fromdt
164
164
  # limit results to those created after this time
165
- # @option options [DateTime] :todt
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::DateTime,
181
- todt: Types::DateTime,
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)
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Thumbtack
4
4
  # Validates and translates user-provided parameters to their Pinboard
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
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'.freeze
11
+ POPULAR_KEY = 'popular'
12
12
 
13
13
  # The key associated with suggested tags
14
14
  #
15
15
  # @api private
16
- RECOMMENDED_KEY = 'recommended'.freeze
16
+ RECOMMENDED_KEY = 'recommended'
17
17
 
18
18
  # A list of popular tags for URL
19
19
  #
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Thumbtack
4
4
  # Handles converting string keys to symbols in a response hash
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Thumbtack
4
4
  # Wraps API calls related to tags
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
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
- fail ValidationError, "#{value} must be true or false"
24
+ raise ValidationError, "#{value} must be true or false"
25
25
  end
26
26
  end
27
27