socialfred 0.1.0 → 0.2.0

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: e085d474bfac2bac95646e7507665360669aee8e48dd282ee128cb3421f813ef
4
- data.tar.gz: 21e8334d24072e40e49dc8e01d2d5bf7dc7ad03ea1df72a31404199a938f39a7
3
+ metadata.gz: a7508235c71840e1bbf248ff2606e33501b550b2d2e0a5ab0488b6c8aeee3767
4
+ data.tar.gz: 8abcd2bc7efa8aeb5e3b98ed158a6add5c85e5f2a7c8ce39bf0c235f86f8deeb
5
5
  SHA512:
6
- metadata.gz: cb9322c4e1589f15a3c2fc58d994b7b84c483fb81bf9de859f02bf2dc8fc5bbbb6313b33bbe540de6e00942c54bbaf2505f5533bdbd6ab73cafcf370dc0a35b4
7
- data.tar.gz: 25d458e2733bc0e00206f809c1de24904f3e4cf9bfbbf575be43fcdd36f2138640e5303e9fef51286ffbc68bb8320da52238ecbb2468a75f448ed662b372df25
6
+ metadata.gz: 28fc572e05b9ee22247c748ea6820d07fea8cafe4544d93266b27a40f33d5896245c365a3fec28b546895c945d5a2219758db571eb7918b172c071e5c45a9bf7
7
+ data.tar.gz: 9c42a0003e1977414070d76ef623bd718f7fc445449ace40f8e2dd8e45f709ef7c29229ede45e1a1a37e4883964d2edbcc8ee1090e0f28138b0bfad48cc18cf5
data/.codeclimate.yml ADDED
@@ -0,0 +1,4 @@
1
+ plugins:
2
+ rubocop:
3
+ enabled: true
4
+ channel: rubocop-0-74
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rspec
4
+
5
+ Style/Documentation:
6
+ Enabled: false
7
+
8
+ Metrics/LineLength:
9
+ Max: 120
10
+
11
+ Metrics/BlockLength:
12
+ Exclude:
13
+ - 'spec/**/*'
14
+ - '**/*.gemspec'
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in socialfred.gemspec
4
6
  gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,65 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ socialfred (0.2.0)
5
+ faraday (>= 0.9.0)
6
+ json (~> 2.2)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.0)
12
+ diff-lcs (1.3)
13
+ faraday (0.17.0)
14
+ multipart-post (>= 1.2, < 3)
15
+ jaro_winkler (1.5.4)
16
+ json (2.2.0)
17
+ multipart-post (2.1.1)
18
+ parallel (1.18.0)
19
+ parser (2.6.5.0)
20
+ ast (~> 2.4.0)
21
+ rainbow (3.0.0)
22
+ rake (10.5.0)
23
+ rspec (3.9.0)
24
+ rspec-core (~> 3.9.0)
25
+ rspec-expectations (~> 3.9.0)
26
+ rspec-mocks (~> 3.9.0)
27
+ rspec-core (3.9.0)
28
+ rspec-support (~> 3.9.0)
29
+ rspec-expectations (3.9.0)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.9.0)
32
+ rspec-mocks (3.9.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.9.0)
35
+ rspec-support (3.9.0)
36
+ rubocop (0.74.0)
37
+ jaro_winkler (~> 1.5.1)
38
+ parallel (~> 1.10)
39
+ parser (>= 2.6)
40
+ rainbow (>= 2.2.2, < 4.0)
41
+ ruby-progressbar (~> 1.7)
42
+ unicode-display_width (>= 1.4.0, < 1.7)
43
+ rubocop-performance (1.5.0)
44
+ rubocop (>= 0.71.0)
45
+ rubocop-rspec (1.36.0)
46
+ rubocop (>= 0.68.1)
47
+ ruby-progressbar (1.10.1)
48
+ unicode-display_width (1.6.0)
49
+ vcr (5.0.0)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ bundler (~> 2.0)
56
+ rake (~> 10.0)
57
+ rspec (~> 3.0)
58
+ rubocop (= 0.74)
59
+ rubocop-performance (~> 1.5)
60
+ rubocop-rspec (~> 1.36)
61
+ socialfred!
62
+ vcr (~> 5.0)
63
+
64
+ BUNDLED WITH
65
+ 2.0.2
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Socialfred
1
+ # Socialfred [![Build Status](https://travis-ci.org/SocialFred/socialfred.svg?branch=master)](https://travis-ci.org/SocialFred/socialfred) [![Maintainability](https://api.codeclimate.com/v1/badges/2cd817600f03aeee7c79/maintainability)](https://codeclimate.com/github/SocialFred/socialfred/maintainability)
2
2
 
3
3
  Social Fred API Client
4
4
 
@@ -20,7 +20,167 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- TODO: Write usage instructions
23
+ ### API Client
24
+
25
+ ```ruby
26
+ api = Socialfred::Api.new(api_key)
27
+ ```
28
+
29
+ ### Social Posts
30
+
31
+ #### Create a social post
32
+
33
+ ```ruby
34
+ api.social_posts.create(
35
+ publish_at: Time.now,
36
+ text: "example text",
37
+ images: [image1, image2],
38
+ options: {
39
+ telegram: {
40
+ alternative_text: "Telegram Alternative Text",
41
+ reply_markup: {
42
+ inline_keyboard: [
43
+ [{text: 'Button', url: 'button_url'}]
44
+ ]
45
+ }
46
+ }
47
+ }
48
+ )
49
+ ```
50
+
51
+ Response:
52
+
53
+ ```ruby
54
+ {
55
+ 'data' => {
56
+ 'id' => '99',
57
+ 'type' => 'social_post',
58
+ 'attributes' => {
59
+ 'text' => 'example text',
60
+ 'created_at' => '2019-10-30T23:54:12.147+01:00',
61
+ 'updated_at' => '2019-10-30T23:54:12.192+01:00',
62
+ 'status' => 'new',
63
+ 'published_at' => '2045-06-01T12:05:00.000+01:00'
64
+ }
65
+ }
66
+ }
67
+ ```
68
+
69
+ #### Update a social post
70
+
71
+ ```ruby
72
+ api.social_posts.update(99, text: 'another text')
73
+ ```
74
+
75
+ Response:
76
+
77
+ ```ruby
78
+ {
79
+ 'data' => {
80
+ 'id' => '99',
81
+ 'type' => 'social_post',
82
+ 'attributes' => {
83
+ 'text' => 'another text',
84
+ 'created_at' => '2019-10-30T23:54:12.147+01:00',
85
+ 'updated_at' => '2019-10-31T00:01:58.128+01:00',
86
+ 'status' => 'new',
87
+ 'published_at' => '2045-06-01T12:05:00.000+01:00'
88
+ }
89
+ }
90
+ }
91
+ ```
92
+
93
+ #### Destroy a social post
94
+
95
+ ```ruby
96
+ api.social_posts.destroy(99)
97
+ ```
98
+
99
+ Response:
100
+
101
+ ```ruby
102
+ {
103
+ 'data' => {
104
+ 'id' => '99',
105
+ 'type' => 'social_post',
106
+ 'attributes' => {
107
+ 'text' => 'another text',
108
+ 'created_at' => '2019-10-30T23:54:12.147+01:00',
109
+ 'updated_at' => '2019-10-31T00:03:30.973+01:00',
110
+ 'status' => 'to_be_deleted',
111
+ 'published_at' => '2045-06-01T12:05:00.000+01:00'
112
+ }
113
+ }
114
+ }
115
+ ```
116
+
117
+ #### List all social posts
118
+
119
+ ```ruby
120
+ api.social_posts.all(page: 1, per_page: 10)
121
+ ```
122
+
123
+ Response:
124
+
125
+ ```ruby
126
+ {
127
+ 'data' => [
128
+ {
129
+ 'id' => '98',
130
+ 'type' => 'social_post',
131
+ 'attributes' => {
132
+ 'text' => 'test1',
133
+ 'created_at' => '2019-10-30T20:54:14.960+01:00',
134
+ 'updated_at' => '2019-10-30T20:54:15.011+01:00',
135
+ 'status' => 'new',
136
+ 'published_at' => '2019-10-30T20:59:14.000+01:00'
137
+ }
138
+ },
139
+ # ...
140
+ {
141
+ 'id' => '95',
142
+ 'type' => 'social_post',
143
+ 'attributes' => {
144
+ 'text' => 'test2',
145
+ 'created_at' => '2019-10-29T22:46:35.857+01:00',
146
+ 'updated_at' => '2019-10-29T23:46:41.645+01:00',
147
+ 'status' => 'published',
148
+ 'published_at' => '2019-10-29T23:46:35.000+01:00'
149
+ }
150
+ }
151
+ ],
152
+ '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'
156
+ },
157
+ 'meta' => { 'total' => 51 }
158
+ }
159
+ ```
160
+
161
+ #### Find one social post
162
+
163
+ ```ruby
164
+ api.social_posts.find(95)
165
+ ```
166
+
167
+ Response:
168
+
169
+ ```ruby
170
+ {
171
+ 'data' => {
172
+ 'id' => '95',
173
+ 'type' => 'social_post',
174
+ 'attributes' => {
175
+ 'text' => 'test2',
176
+ 'created_at' => '2019-10-29T22:46:35.857+01:00',
177
+ 'updated_at' => '2019-10-29T23:46:41.645+01:00',
178
+ 'status' => 'published',
179
+ 'published_at' => '2019-10-29T23:46:35.000+01:00'
180
+ }
181
+ }
182
+ }
183
+ ```
24
184
 
25
185
  ## Development
26
186
 
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "socialfred"
4
+ require 'bundler/setup'
5
+ require 'socialfred'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "socialfred"
10
11
  # require "pry"
11
12
  # Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start(__FILE__)
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'socialfred/social_posts'
5
+
6
+ module Socialfred
7
+ class Api
8
+ attr_reader :api_key, :api_url
9
+
10
+ API_URL = 'https://socialfred.com/api/'
11
+
12
+ def initialize(api_key, api_url: API_URL)
13
+ @api_key = api_key
14
+ @api_url = api_url
15
+ end
16
+
17
+ def social_posts
18
+ @social_posts ||= SocialPosts.new(api_key, api_url: api_url)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,71 @@
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Socialfred
2
- VERSION = "0.1.0"
4
+ VERSION = '0.2.0'
3
5
  end
data/lib/socialfred.rb CHANGED
@@ -1,4 +1,10 @@
1
- require "socialfred/version"
1
+ # frozen_string_literal: true
2
+
3
+ require 'socialfred/version'
4
+
5
+ require 'socialfred/api'
6
+
7
+ require 'json'
2
8
 
3
9
  module Socialfred
4
10
  class Error < StandardError; end
data/socialfred.gemspec CHANGED
@@ -1,32 +1,41 @@
1
- lib = File.expand_path("lib", __dir__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "socialfred/version"
5
+ require 'socialfred/version'
4
6
 
5
7
  Gem::Specification.new do |spec|
6
- spec.name = "socialfred"
8
+ spec.name = 'socialfred'
7
9
  spec.version = Socialfred::VERSION
8
- spec.authors = ["Alexey Krasnoperov"]
9
- spec.email = ["info@socialfred.com"]
10
+ spec.authors = ['Alexey Krasnoperov']
11
+ spec.email = ['info@socialfred.com']
10
12
 
11
- spec.summary = %q{Social Fred API Client}
12
- spec.description = %q{Social Fred API Client: schedule social posts to multiple social networks}
13
- spec.homepage = "https://github.com/SocialFred/socialfred"
14
- spec.license = "MIT"
13
+ spec.summary = 'Social Fred API Client'
14
+ spec.description = 'Social Fred API Client: schedule social posts to multiple social networks'
15
+ spec.homepage = 'https://github.com/socialfred/socialfred'
16
+ spec.license = 'MIT'
15
17
 
16
- spec.metadata["homepage_uri"] = spec.homepage
17
- spec.metadata["source_code_uri"] = "https://github.com/SocialFred/socialfred"
18
- spec.metadata["changelog_uri"] = "https://github.com/SocialFred/socialfred"
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+ spec.metadata['source_code_uri'] = 'https://github.com/socialfred/socialfred'
20
+ spec.metadata['changelog_uri'] = 'https://github.com/socialfred/socialfred'
19
21
 
20
22
  # Specify which files should be added to the gem when it is released.
21
23
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
25
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
26
  end
25
- spec.bindir = "exe"
27
+ spec.bindir = 'exe'
26
28
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
- spec.require_paths = ["lib"]
29
+ spec.require_paths = ['lib']
30
+
31
+ spec.add_runtime_dependency 'faraday', '>= 0.9.0'
32
+ spec.add_runtime_dependency 'json', '~> 2.2'
28
33
 
29
- spec.add_development_dependency "bundler", "~> 2.0"
30
- spec.add_development_dependency "rake", "~> 10.0"
31
- spec.add_development_dependency "rspec", "~> 3.0"
34
+ spec.add_development_dependency 'bundler', '~> 2.0'
35
+ spec.add_development_dependency 'rake', '~> 10.0'
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'
40
+ spec.add_development_dependency 'vcr', '~> 5.0'
32
41
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socialfred
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
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-27 00:00:00.000000000 Z
11
+ date: 2019-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.2'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: bundler
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +80,62 @@ dependencies:
52
80
  - - "~>"
53
81
  - !ruby/object:Gem::Version
54
82
  version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: '0.74'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: '0.74'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-performance
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.5'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.5'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.36'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.36'
125
+ - !ruby/object:Gem::Dependency
126
+ name: vcr
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '5.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '5.0'
55
139
  description: 'Social Fred API Client: schedule social posts to multiple social networks'
56
140
  email:
57
141
  - info@socialfred.com
@@ -59,25 +143,30 @@ executables: []
59
143
  extensions: []
60
144
  extra_rdoc_files: []
61
145
  files:
146
+ - ".codeclimate.yml"
62
147
  - ".gitignore"
63
148
  - ".rspec"
149
+ - ".rubocop.yml"
64
150
  - ".travis.yml"
65
151
  - Gemfile
152
+ - Gemfile.lock
66
153
  - LICENSE.txt
67
154
  - README.md
68
155
  - Rakefile
69
156
  - bin/console
70
157
  - bin/setup
71
158
  - lib/socialfred.rb
159
+ - lib/socialfred/api.rb
160
+ - lib/socialfred/social_posts.rb
72
161
  - lib/socialfred/version.rb
73
162
  - socialfred.gemspec
74
- homepage: https://github.com/SocialFred/socialfred
163
+ homepage: https://github.com/socialfred/socialfred
75
164
  licenses:
76
165
  - MIT
77
166
  metadata:
78
- homepage_uri: https://github.com/SocialFred/socialfred
79
- source_code_uri: https://github.com/SocialFred/socialfred
80
- changelog_uri: https://github.com/SocialFred/socialfred
167
+ homepage_uri: https://github.com/socialfred/socialfred
168
+ source_code_uri: https://github.com/socialfred/socialfred
169
+ changelog_uri: https://github.com/socialfred/socialfred
81
170
  post_install_message:
82
171
  rdoc_options: []
83
172
  require_paths: