socialfred 0.2.0 → 1.0.1

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
  SHA256:
3
- metadata.gz: a7508235c71840e1bbf248ff2606e33501b550b2d2e0a5ab0488b6c8aeee3767
4
- data.tar.gz: 8abcd2bc7efa8aeb5e3b98ed158a6add5c85e5f2a7c8ce39bf0c235f86f8deeb
3
+ metadata.gz: 7f11030d6f2232279f9c201c4b8fc2296e5e93a56f5559ec087e11cfadeff614
4
+ data.tar.gz: e626c0dedae80f84e81b3c0fdb6695374caf2b112d7e1c7bb82acaa5c43e65ba
5
5
  SHA512:
6
- metadata.gz: 28fc572e05b9ee22247c748ea6820d07fea8cafe4544d93266b27a40f33d5896245c365a3fec28b546895c945d5a2219758db571eb7918b172c071e5c45a9bf7
7
- data.tar.gz: 9c42a0003e1977414070d76ef623bd718f7fc445449ace40f8e2dd8e45f709ef7c29229ede45e1a1a37e4883964d2edbcc8ee1090e0f28138b0bfad48cc18cf5
6
+ metadata.gz: ddd5aa659171f8698aae7dd5f99f606b94eaac8390733d384ea869dc7f9c721f13a87b9ac30969f9b71b5276262bedad22b4e1c2f5d2293a6921f1b5dcf94087
7
+ data.tar.gz: 66fa6643ddab3068a02a485014c5abfa6abf51e41057110fe8257a603e3c8a080225d78dd90155e962962f665b1e11f3c643c50064094ea1d0e847205baa8743
@@ -12,3 +12,33 @@ Metrics/BlockLength:
12
12
  Exclude:
13
13
  - 'spec/**/*'
14
14
  - '**/*.gemspec'
15
+
16
+ ### DEFAULT RULES
17
+ Layout/EmptyLinesAroundAttributeAccessor:
18
+ Enabled: true
19
+ Layout/SpaceAroundMethodCallOperator:
20
+ Enabled: true
21
+ Lint/DeprecatedOpenSSLConstant:
22
+ Enabled: true
23
+ Lint/MixedRegexpCaptureTypes:
24
+ Enabled: true
25
+ Lint/RaiseException:
26
+ Enabled: true
27
+ Lint/StructNewOverride:
28
+ Enabled: true
29
+ Style/ExponentialNotation:
30
+ Enabled: true
31
+ Style/HashEachMethods:
32
+ Enabled: true
33
+ Style/HashTransformKeys:
34
+ Enabled: true
35
+ Style/HashTransformValues:
36
+ Enabled: true
37
+ Style/RedundantFetchBlock:
38
+ Enabled: true
39
+ Style/RedundantRegexpCharacterClass:
40
+ Enabled: true
41
+ Style/RedundantRegexpEscape:
42
+ Enabled: true
43
+ Style/SlicingWithRange:
44
+ Enabled: true
@@ -1,25 +1,26 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- socialfred (0.2.0)
4
+ socialfred (1.0.1)
5
5
  faraday (>= 0.9.0)
6
6
  json (~> 2.2)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- ast (2.4.0)
11
+ ast (2.4.1)
12
12
  diff-lcs (1.3)
13
- faraday (0.17.0)
13
+ faraday (1.0.1)
14
14
  multipart-post (>= 1.2, < 3)
15
- jaro_winkler (1.5.4)
16
- json (2.2.0)
15
+ json (2.3.1)
17
16
  multipart-post (2.1.1)
18
- parallel (1.18.0)
19
- parser (2.6.5.0)
20
- ast (~> 2.4.0)
17
+ parallel (1.19.2)
18
+ parser (2.7.1.4)
19
+ ast (~> 2.4.1)
21
20
  rainbow (3.0.0)
22
- rake (10.5.0)
21
+ rake (13.0.1)
22
+ regexp_parser (1.7.1)
23
+ rexml (3.2.4)
23
24
  rspec (3.9.0)
24
25
  rspec-core (~> 3.9.0)
25
26
  rspec-expectations (~> 3.9.0)
@@ -33,19 +34,23 @@ GEM
33
34
  diff-lcs (>= 1.2.0, < 2.0)
34
35
  rspec-support (~> 3.9.0)
35
36
  rspec-support (3.9.0)
36
- rubocop (0.74.0)
37
- jaro_winkler (~> 1.5.1)
37
+ rubocop (0.86.0)
38
38
  parallel (~> 1.10)
39
- parser (>= 2.6)
39
+ parser (>= 2.7.0.1)
40
40
  rainbow (>= 2.2.2, < 4.0)
41
+ regexp_parser (>= 1.7)
42
+ rexml
43
+ rubocop-ast (>= 0.0.3, < 1.0)
41
44
  ruby-progressbar (~> 1.7)
42
- unicode-display_width (>= 1.4.0, < 1.7)
43
- rubocop-performance (1.5.0)
45
+ unicode-display_width (>= 1.4.0, < 2.0)
46
+ rubocop-ast (0.1.0)
47
+ parser (>= 2.7.0.1)
48
+ rubocop-performance (1.6.1)
44
49
  rubocop (>= 0.71.0)
45
- rubocop-rspec (1.36.0)
50
+ rubocop-rspec (1.40.0)
46
51
  rubocop (>= 0.68.1)
47
52
  ruby-progressbar (1.10.1)
48
- unicode-display_width (1.6.0)
53
+ unicode-display_width (1.7.0)
49
54
  vcr (5.0.0)
50
55
 
51
56
  PLATFORMS
@@ -53,13 +58,13 @@ PLATFORMS
53
58
 
54
59
  DEPENDENCIES
55
60
  bundler (~> 2.0)
56
- rake (~> 10.0)
61
+ rake (~> 13.0)
57
62
  rspec (~> 3.0)
58
- rubocop (= 0.74)
59
- rubocop-performance (~> 1.5)
60
- rubocop-rspec (~> 1.36)
63
+ rubocop (~> 0.86.0)
64
+ rubocop-performance (~> 1.6.1)
65
+ rubocop-rspec (~> 1.40.0)
61
66
  socialfred!
62
67
  vcr (~> 5.0)
63
68
 
64
69
  BUNDLED WITH
65
- 2.0.2
70
+ 2.1.2
data/README.md CHANGED
@@ -31,7 +31,9 @@ api = Socialfred::Api.new(api_key)
31
31
  #### Create a social post
32
32
 
33
33
  ```ruby
34
- api.social_posts.create(
34
+ image1 = {data: Base64.encode64(image.download), filename: 'image.jpeg', content_type: 'image/jpeg'}
35
+ # ...
36
+ api.publications.create(
35
37
  publish_at: Time.now,
36
38
  text: "example text",
37
39
  images: [image1, image2],
@@ -54,7 +56,7 @@ Response:
54
56
  {
55
57
  'data' => {
56
58
  'id' => '99',
57
- 'type' => 'social_post',
59
+ 'type' => 'publication',
58
60
  'attributes' => {
59
61
  'text' => 'example text',
60
62
  'created_at' => '2019-10-30T23:54:12.147+01:00',
@@ -69,7 +71,7 @@ Response:
69
71
  #### Update a social post
70
72
 
71
73
  ```ruby
72
- api.social_posts.update(99, text: 'another text')
74
+ api.publications.update(99, text: 'another text')
73
75
  ```
74
76
 
75
77
  Response:
@@ -78,7 +80,7 @@ Response:
78
80
  {
79
81
  'data' => {
80
82
  'id' => '99',
81
- 'type' => 'social_post',
83
+ 'type' => 'publication',
82
84
  'attributes' => {
83
85
  'text' => 'another text',
84
86
  'created_at' => '2019-10-30T23:54:12.147+01:00',
@@ -93,7 +95,7 @@ Response:
93
95
  #### Destroy a social post
94
96
 
95
97
  ```ruby
96
- api.social_posts.destroy(99)
98
+ api.publications.destroy(99)
97
99
  ```
98
100
 
99
101
  Response:
@@ -102,7 +104,7 @@ Response:
102
104
  {
103
105
  'data' => {
104
106
  'id' => '99',
105
- 'type' => 'social_post',
107
+ 'type' => 'publication',
106
108
  'attributes' => {
107
109
  'text' => 'another text',
108
110
  'created_at' => '2019-10-30T23:54:12.147+01:00',
@@ -117,7 +119,7 @@ Response:
117
119
  #### List all social posts
118
120
 
119
121
  ```ruby
120
- api.social_posts.all(page: 1, per_page: 10)
122
+ api.publications.all(page: 1, per_page: 10)
121
123
  ```
122
124
 
123
125
  Response:
@@ -127,7 +129,7 @@ Response:
127
129
  'data' => [
128
130
  {
129
131
  'id' => '98',
130
- 'type' => 'social_post',
132
+ 'type' => 'publication',
131
133
  'attributes' => {
132
134
  'text' => 'test1',
133
135
  'created_at' => '2019-10-30T20:54:14.960+01:00',
@@ -139,7 +141,7 @@ Response:
139
141
  # ...
140
142
  {
141
143
  'id' => '95',
142
- 'type' => 'social_post',
144
+ 'type' => 'publication',
143
145
  'attributes' => {
144
146
  'text' => 'test2',
145
147
  'created_at' => '2019-10-29T22:46:35.857+01:00',
@@ -150,9 +152,9 @@ Response:
150
152
  }
151
153
  ],
152
154
  'links' => {
153
- 'first' => 'https://socialfred.com/api/social_posts?page=1&per_page=10',
154
- 'last' => 'https://socialfred.com/api/social_posts?page=26&per_page=10',
155
- 'next' => 'https://socialfred.com/api/social_posts?page=2&per_page=10'
155
+ 'first' => 'https://api.socialfred.com/publications?page=1&per_page=10',
156
+ 'last' => 'https://api.socialfred.com/publications?page=26&per_page=10',
157
+ 'next' => 'https://api.socialfred.com/publications?page=2&per_page=10'
156
158
  },
157
159
  'meta' => { 'total' => 51 }
158
160
  }
@@ -161,7 +163,7 @@ Response:
161
163
  #### Find one social post
162
164
 
163
165
  ```ruby
164
- api.social_posts.find(95)
166
+ api.publications.find(95)
165
167
  ```
166
168
 
167
169
  Response:
@@ -170,7 +172,7 @@ Response:
170
172
  {
171
173
  'data' => {
172
174
  'id' => '95',
173
- 'type' => 'social_post',
175
+ 'type' => 'publication',
174
176
  'attributes' => {
175
177
  'text' => 'test2',
176
178
  'created_at' => '2019-10-29T22:46:35.857+01:00',
@@ -1,21 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'faraday'
4
- require 'socialfred/social_posts'
3
+ require 'socialfred/publications'
5
4
 
6
5
  module Socialfred
7
6
  class Api
8
7
  attr_reader :api_key, :api_url
9
8
 
10
- API_URL = 'https://socialfred.com/api/'
9
+ API_URL = 'https://api.socialfred.com/'
11
10
 
12
11
  def initialize(api_key, api_url: API_URL)
13
12
  @api_key = api_key
14
13
  @api_url = api_url
15
14
  end
16
15
 
17
- def social_posts
18
- @social_posts ||= SocialPosts.new(api_key, api_url: api_url)
16
+ def publications
17
+ @publications ||= Publications.new(api_key, api_url: api_url)
19
18
  end
20
19
  end
21
20
  end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'socialfred/requester'
4
+ require 'time'
5
+
6
+ module Socialfred
7
+ class Publications
8
+ attr_reader :api_key, :api_url
9
+
10
+ ENDPOINT = 'publications'
11
+
12
+ def initialize(api_key, api_url:)
13
+ @api_key = api_key
14
+ @api_url = api_url
15
+ end
16
+
17
+ def all(page: 1, per_page: 10)
18
+ response = requester.get(ENDPOINT, page: page, per_page: per_page)
19
+
20
+ raise Socialfred::Error, response.body unless response.status == 200
21
+
22
+ JSON.parse(response.body)
23
+ end
24
+
25
+ def find(publication_id)
26
+ response = requester.get(ENDPOINT + "/#{publication_id}")
27
+
28
+ raise Socialfred::Error, response.body unless response.status == 200
29
+
30
+ JSON.parse(response.body)
31
+ end
32
+
33
+ def create(publish_at: nil, text:, images: nil, options: nil)
34
+ check_images(images) if images
35
+
36
+ publish_at = Time.parse(publish_at.to_s).iso8601 if publish_at
37
+ parameters = { publication: { published_at: publish_at, text: text, images: images, options: options }.compact }
38
+ response = requester.post(ENDPOINT, parameters)
39
+
40
+ raise Socialfred::Error, response.body unless response.status == 200
41
+
42
+ JSON.parse(response.body)
43
+ end
44
+
45
+ def update(publication_id, publish_at: nil, text: nil, images: nil, options: nil)
46
+ check_images(images) if images
47
+
48
+ publish_at = Time.parse(publish_at.to_s).iso8601 if publish_at
49
+ parameters = { publication: { published_at: publish_at, text: text, images: images, options: options }.compact }
50
+ response = requester.put(ENDPOINT + "/#{publication_id}", parameters)
51
+
52
+ raise Socialfred::Error, response.body unless response.status == 200
53
+
54
+ JSON.parse(response.body)
55
+ end
56
+
57
+ def destroy(publication_id)
58
+ response = requester.delete(ENDPOINT + "/#{publication_id}")
59
+
60
+ raise Socialfred::Error, response.body unless response.status == 200
61
+
62
+ JSON.parse(response.body)
63
+ end
64
+
65
+ private
66
+
67
+ def check_images(images)
68
+ raise(Socialfred::Error, 'images must be array') unless images.is_a?(Array)
69
+ return if images.all? { |image| image.key?(:data) && image.key?(:filename) && image.key?(:content_type) }
70
+
71
+ raise(
72
+ Socialfred::Error,
73
+ 'images must contain the following attributes: data (base64 encoded image), filename and content_type'
74
+ )
75
+ end
76
+
77
+ def requester
78
+ @requester ||= Requester.new(api_key, api_url)
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+
5
+ module Socialfred
6
+ class Requester
7
+ attr_reader :api_key, :api_url
8
+
9
+ CONTENT_TYPE = 'application/json'
10
+
11
+ def initialize(api_key, api_url)
12
+ @api_key = api_key
13
+ @api_url = api_url
14
+ end
15
+
16
+ def get(endpoint, parameters = nil)
17
+ conn.get(endpoint, parameters) do |req|
18
+ req.headers[:content_type] = CONTENT_TYPE
19
+ end
20
+ end
21
+
22
+ def post(endpoint, parameters = nil)
23
+ conn.post(endpoint) do |req|
24
+ req.headers[:content_type] = CONTENT_TYPE
25
+ req.body = JSON.generate(parameters)
26
+ end
27
+ end
28
+
29
+ def put(endpoint, parameters = nil)
30
+ conn.put(endpoint) do |req|
31
+ req.headers[:content_type] = CONTENT_TYPE
32
+ req.body = JSON.generate(parameters)
33
+ end
34
+ end
35
+
36
+ def delete(endpoint)
37
+ conn.delete(endpoint) do |req|
38
+ req.headers[:content_type] = CONTENT_TYPE
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def conn
45
+ @conn ||= Faraday.new(url: api_url) do |faraday|
46
+ faraday.adapter Faraday.default_adapter
47
+ faraday.headers['Api-Key'] = api_key
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Socialfred
4
- VERSION = '0.2.0'
4
+ VERSION = '1.0.1'
5
5
  end
@@ -32,10 +32,10 @@ Gem::Specification.new do |spec|
32
32
  spec.add_runtime_dependency 'json', '~> 2.2'
33
33
 
34
34
  spec.add_development_dependency 'bundler', '~> 2.0'
35
- spec.add_development_dependency 'rake', '~> 10.0'
35
+ spec.add_development_dependency 'rake', '~> 13.0'
36
36
  spec.add_development_dependency 'rspec', '~> 3.0'
37
- spec.add_development_dependency 'rubocop', '0.74'
38
- spec.add_development_dependency 'rubocop-performance', '~> 1.5'
39
- spec.add_development_dependency 'rubocop-rspec', '~> 1.36'
37
+ spec.add_development_dependency 'rubocop', '~> 0.86.0'
38
+ spec.add_development_dependency 'rubocop-performance', '~> 1.6.1'
39
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.40.0'
40
40
  spec.add_development_dependency 'vcr', '~> 5.0'
41
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socialfred
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Krasnoperov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-31 00:00:00.000000000 Z
11
+ date: 2020-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '13.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: '13.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -84,44 +84,44 @@ dependencies:
84
84
  name: rubocop
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '='
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0.74'
89
+ version: 0.86.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '='
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0.74'
96
+ version: 0.86.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rubocop-performance
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '1.5'
103
+ version: 1.6.1
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '1.5'
110
+ version: 1.6.1
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rubocop-rspec
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '1.36'
117
+ version: 1.40.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '1.36'
124
+ version: 1.40.0
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: vcr
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -157,7 +157,8 @@ files:
157
157
  - bin/setup
158
158
  - lib/socialfred.rb
159
159
  - lib/socialfred/api.rb
160
- - lib/socialfred/social_posts.rb
160
+ - lib/socialfred/publications.rb
161
+ - lib/socialfred/requester.rb
161
162
  - lib/socialfred/version.rb
162
163
  - socialfred.gemspec
163
164
  homepage: https://github.com/socialfred/socialfred
@@ -182,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
183
  - !ruby/object:Gem::Version
183
184
  version: '0'
184
185
  requirements: []
185
- rubygems_version: 3.0.3
186
+ rubygems_version: 3.1.2
186
187
  signing_key:
187
188
  specification_version: 4
188
189
  summary: Social Fred API Client
@@ -1,71 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'time'
4
-
5
- module Socialfred
6
- class SocialPosts
7
- attr_reader :api_key, :api_url
8
-
9
- ENDPOINT = 'social_posts'
10
-
11
- def initialize(api_key, api_url:)
12
- @api_key = api_key
13
- @api_url = api_url
14
- end
15
-
16
- def all(page: 1, per_page: 10)
17
- response = conn.get(ENDPOINT, page: page, per_page: per_page)
18
-
19
- raise Socialfred::Error unless response.status == 200
20
-
21
- JSON.parse(response.body)
22
- end
23
-
24
- def find(social_post_id)
25
- response = conn.get(ENDPOINT + "/#{social_post_id}")
26
-
27
- raise Socialfred::Error unless response.status == 200
28
-
29
- JSON.parse(response.body)
30
- end
31
-
32
- def create(publish_at: nil, text:, images: nil, options: nil)
33
- publish_at = Time.parse(publish_at.to_s).iso8601 if publish_at
34
- parameters = { social_post: { published_at: publish_at, text: text, images: images, options: options }.compact }
35
- response = conn.post(ENDPOINT, parameters)
36
-
37
- raise Socialfred::Error unless response.status == 200
38
-
39
- JSON.parse(response.body)
40
- end
41
-
42
- def update(social_post_id, publish_at: nil, text:, images: nil, options: nil)
43
- publish_at = Time.parse(publish_at.to_s).iso8601 if publish_at
44
- parameters = { social_post: { published_at: publish_at, text: text, images: images, options: options }.compact }
45
- response = conn.put(ENDPOINT + "/#{social_post_id}", parameters)
46
-
47
- raise Socialfred::Error unless response.status == 200
48
-
49
- JSON.parse(response.body)
50
- end
51
-
52
- def destroy(social_post_id)
53
- response = conn.delete(ENDPOINT + "/#{social_post_id}")
54
-
55
- raise Socialfred::Error unless response.status == 200
56
-
57
- JSON.parse(response.body)
58
- end
59
-
60
- private
61
-
62
- def conn
63
- @conn ||= Faraday.new(url: api_url) do |faraday|
64
- faraday.request :multipart
65
- faraday.request :url_encoded
66
- faraday.adapter Faraday.default_adapter
67
- faraday.headers['Api-Key'] = api_key
68
- end
69
- end
70
- end
71
- end