mediumite 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e94cf3460cb0d169c187700e4e021ab1c4b33510
4
+ data.tar.gz: 13f7a4f5eea070c4ebf4ddbf6e0c4c42646bf506
5
+ SHA512:
6
+ metadata.gz: 853597e576e7c374d1c22229941c21e227e6776d50e8d12f6251ea5dc4b34e98561ca0b55cffed64a7cef86e218408685763e7fe1d599d99f47ece2dbd338574
7
+ data.tar.gz: b1af352c0d6c3f5e495177cf53fb2f17b6773aae4ff54881b4772d960935f0ab980aaae2878429e7b8a2443a223c211fb9f85f320dd2e07bdbb3fbfca65faae8
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mediumite.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # Mediumite [![CircleCI](https://circleci.com/gh/rejasupotaro/mediumite.svg?style=svg)](https://circleci.com/gh/rejasupotaro/mediumite)
2
+
3
+ This is simple wrapper for the Medium API written in Ruby.
4
+ For full API documentation, see [Medium/medium-api-docs: Documentation for Medium's OAuth2 API](https://github.com/Medium/medium-api-docs#32-publications)
5
+
6
+ # Usage
7
+
8
+ ## Authentication
9
+
10
+ In order to publish on behalf of a Medium account, you will need an access token. Medium offers two ways to acquire an access token: browser-based OAuth authentication, and self-issued access tokens. Currently this library supports only self-issued access tokens.
11
+
12
+ You can generate/revoke an access token from the [Settings page](https://medium.com/me/settings) of your Medium account.
13
+
14
+ Using the access token, initlize `Mediumite::Client`.
15
+
16
+ ```ruby
17
+ client = Mediumite::Client.new(token: your_access_token)
18
+ ```
19
+
20
+ ## Resources
21
+
22
+ ### Users
23
+
24
+ #### Getting the authenticated user’s details
25
+
26
+ Returns details of the user who has granted permission to the application.
27
+
28
+ Example:
29
+
30
+ ```ruby
31
+ > client.user
32
+ => {:id=>"5303d74c64f66366f00cb9b2a94f3251bf5",
33
+ :username=>"majelbstoat",
34
+ :name=>"Jamie Talbot",
35
+ :url=>"https://medium.com/@majelbstoat",
36
+ :imageUrl=>"https://images.medium.com/0*fkfQiTzT7TlUGGyI.png"}
37
+ ```
38
+
39
+ ### Publications
40
+
41
+ #### Listing the user’s publications
42
+
43
+ Returns a full list of publications that the user is related to in some way: This includes all publications the user is subscribed to, writes to, or edits.
44
+
45
+ Example:
46
+
47
+ ```ruby
48
+ > client.get_publications
49
+ => [{:id=>"b969ac62a46b",
50
+ :name=>"About Medium",
51
+ :description=>"What is this thing and how does it work?",
52
+ :url=>"https://medium.com/about",
53
+ :imageUrl=>"https://cdn-images-1.medium.com/fit/c/200/200/0*ae1jbP_od0W6EulE.jpeg"}
54
+ ,
55
+ {:id=>"b45573563f5a",
56
+ :name=>"Developers",
57
+ :description=>"Medium’s Developer resources",
58
+ :url=>"https://medium.com/developers",
59
+ :imageUrl=>"https://cdn-images-1.medium.com/fit/c/200/200/1*ccokMT4VXmDDO1EoQQHkzg@2x.png"}
60
+ ]
61
+ ```
62
+
63
+ ### Posts
64
+
65
+ #### Creating a post
66
+
67
+ Creates a post on the authenticated user’s profile.
68
+
69
+ Example:
70
+
71
+ ```ruby
72
+ > post = Mediumite::Post.new(title: "Liverpool FC", body: "# Liverpool FC\nYou’ll never walk alone.")
73
+ > client.create_post(post)
74
+ => {:id=>"e6f36a",
75
+ :title=>"Liverpool FC",
76
+ :authorId=>"5303d74c64f66366f00cb9b2a94f3251bf5",
77
+ :url=>"https://medium.com/@majelbstoat/liverpool-fc-e6f36a",
78
+ :canonicalUrl=>"http://jamietalbot.com/posts/liverpool-fc",
79
+ :publishStatus=>"draft",
80
+ :publishedAt=>1442286338435,
81
+ :license=>"",
82
+ :licenseUrl=>"https://medium.com/policy/9db0094a1e0f"
83
+ :tags=>[]}
84
+ ```
85
+
86
+ You can specify these parameters below.
87
+
88
+ | Parameter | Type | Required? | Description |
89
+ |----|----|----|----|
90
+ | title | string | required | The title of the post. |
91
+ | body | string | required | The body of the post, in a valid, semantic, markdown or HTML fragment. Further markups may be supported in the future. For a full list of accepted HTML tags, see [here](https://medium.com/@katie/a4367010924e). |
92
+ | format | string | optional | The format of the "body" field. There are two valid values, "markdown", and "html". The default is "markdown" |
93
+ | tags | string array | optional | Tags to classify the post. Only the first three will be used. Tags longer than 25 characters will be ignored. |
94
+ | publish_status | string | optional | The status of the post. Valid values are “public”, “draft”, or “unlisted”. The default is “draft”. |
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mediumite"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/circle.yml ADDED
@@ -0,0 +1,21 @@
1
+ ## Customize the test machine
2
+ machine:
3
+
4
+ # Version of ruby to use
5
+ ruby:
6
+ version:
7
+ 2.2.3
8
+
9
+ ## Customize dependencies
10
+ dependencies:
11
+ pre:
12
+ - gem install bundler --pre
13
+
14
+ override:
15
+ - bundle install -j4: # note ':' here
16
+ timeout: 180 # fail if command has no output for 3 minutes
17
+
18
+ ## Customize test commands
19
+ test:
20
+ override:
21
+ - bundle exec rspec
data/lib/mediumite.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "mediumite/version"
2
+ require "mediumite/client"
3
+ require "mediumite/post"
4
+
5
+ module Mediumite
6
+ end
@@ -0,0 +1,46 @@
1
+ require "sawyer"
2
+
3
+ module Mediumite
4
+ class Client
5
+ def initialize(options = {})
6
+ @options = options
7
+ end
8
+
9
+ def inspect
10
+ inspected = super
11
+ inspected = inspected.gsub! token, "#{'*'*token.length}" if token
12
+ inspected
13
+ end
14
+
15
+ def token
16
+ @options[:token]
17
+ end
18
+
19
+ def agent
20
+ @agent ||= Sawyer::Agent.new("https://api.medium.com/v1") do |http|
21
+ http.headers[:content_type] = "application/json"
22
+ http.authorization "Bearer", token
23
+ end
24
+ end
25
+
26
+ def request(method, path, data = {})
27
+ agent.call(method, URI::Parser.new.escape(path.to_s), data).data.data
28
+ end
29
+
30
+ def user
31
+ @user ||= request(:get, "me")
32
+ end
33
+
34
+ def get_publications
35
+ request(:get, "users/#{user.id}/publications")
36
+ end
37
+
38
+ def create_post(post)
39
+ if post.under_publication?
40
+ request(:post, "publications/#{post.publication_id}/posts", post.to_json)
41
+ else
42
+ request(:post, "users/#{user.id}/posts", post.to_json)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,28 @@
1
+ require "json"
2
+
3
+ module Mediumite
4
+ class Post
5
+ def initialize(content)
6
+ @content = content
7
+ end
8
+
9
+ def publication_id
10
+ @content[:publication_id]
11
+ end
12
+
13
+ def under_publication?
14
+ !!@content[:publication_id]
15
+ end
16
+
17
+ def to_json
18
+ {
19
+ title: @content[:title],
20
+ contentFormat: @content[:format] ||= "markdown",
21
+ content: @content[:body],
22
+ canonicalUrl: @content[:canonical_url],
23
+ tags: @content[:tags],
24
+ publishStatus: @content[:publish_status] ||= "draft"
25
+ }.to_json
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module Mediumite
2
+ VERSION = "0.1.0"
3
+ end
data/mediumite.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mediumite/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mediumite"
8
+ spec.version = Mediumite::VERSION
9
+ spec.authors = ["Kentaro Takiguchi"]
10
+ spec.email = ["takiguchi0817@gmail.com"]
11
+
12
+ spec.summary = %q{Simple wrapper for the Medium API written in Ruby.}
13
+ spec.description = %q{Simple wrapper for the Medium API written in Ruby.}
14
+ spec.homepage = "https://github.com/rejasupotaro/mediumite"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.11"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "sawyer"
25
+ spec.add_development_dependency "pry"
26
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mediumite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kentaro Takiguchi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sawyer
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Simple wrapper for the Medium API written in Ruby.
84
+ email:
85
+ - takiguchi0817@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - README.md
93
+ - Rakefile
94
+ - bin/console
95
+ - bin/setup
96
+ - circle.yml
97
+ - lib/mediumite.rb
98
+ - lib/mediumite/client.rb
99
+ - lib/mediumite/post.rb
100
+ - lib/mediumite/version.rb
101
+ - mediumite.gemspec
102
+ homepage: https://github.com/rejasupotaro/mediumite
103
+ licenses: []
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.4.5.1
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Simple wrapper for the Medium API written in Ruby.
125
+ test_files: []