gdocs 0.1.0 → 0.1.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: 56a31c9591bcfe1c8e4aaee963bc42b86c21cdb4580fab55b4a26cc0c2bc27b5
4
- data.tar.gz: 1d18245cc71e87873f4c895165b3091609d2c2faf209baff427a68baff83fc0a
3
+ metadata.gz: 0e5270dc851470cb322513a5eca8e2f791cc45059e4f67c813ce43715abf1540
4
+ data.tar.gz: 4e92ee79013cd935a66d0aeee185f239c1b310c8a23a5cabd62136b5c65943cf
5
5
  SHA512:
6
- metadata.gz: 512a267fd163ceb8469300624ca30dfac5a288a78df5db34d9070d1afe4844fc42c54f842a29fcc6348772a6adb28b08418aa56dd8cb95777afe28fc7bd762c5
7
- data.tar.gz: 945894e909204594550416f3948cf21eefd6c3d65b6f45344cbf6120ae093b93e0b1f3037b617809df3cc83c951bc6cfd11babe85d4b07b20ff0274a847c1c4d
6
+ metadata.gz: 895dcc27e458d12c1762ebb1389aad8daca2dbd7b1f915c166f9759645d196815aeec1998d5fb0b23d7b575193b3997cb3c51e0c853263e115ab835d06d2b23b
7
+ data.tar.gz: e3e771ef800d32c7930abd078ee01514844cfcfc5738fa78ff3a7109cfc32212119f681b1f8085ac006b4c619523832d8be4f16b53734b3e7506008ac38639f5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.1] - 2022-10-09
4
+
5
+ - Start features: add a doc with title, get the `title` with `document_id`
6
+
3
7
  ## [0.1.0] - 2022-10-06
4
8
 
5
9
  - Initial release
data/README.md CHANGED
@@ -16,7 +16,18 @@ If bundler is not being used to manage dependencies, install the gem by executin
16
16
 
17
17
  ## Usage
18
18
 
19
- TODO: Write usage instructions here
19
+ As of today, we only have `Gdocs::Models::Document#run_get` and `Gdocs::Models::Document#run_create`
20
+ ```rb
21
+ require 'gdocs'
22
+
23
+ d = Gdocs::Models::Document.new
24
+ d.run_create(title: "Jimmy")
25
+ # => "1qpN_MR_i1rnu7-MD03JKUGlTvOT2GFgr5uyhhsvJ2Z8"
26
+
27
+ d.run_get('1qpN_MR_i1rnu7-MD03JKUGlTvOT2GFgr5uyhhsvJ2Z8') if ENV['GDOCS_AUTH_TOKEN']
28
+ d.title
29
+ # => "Jimmy"
30
+ ```
20
31
 
21
32
  ## Development
22
33
 
data/gdocs.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/gdocs/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "gdocs"
7
+ spec.version = Gdocs::VERSION
8
+ spec.authors = ["Kang-Kyu Lee"]
9
+ spec.email = ["kangkyu1111@gmail.com"]
10
+
11
+ spec.summary = "Use Google Docs API and do something"
12
+ spec.description = "Generate or modify docs by API requests"
13
+ spec.homepage = "https://rubygems.org/gems/gdocs"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/kangkyu/gdocs"
21
+ spec.metadata["changelog_uri"] = "https://github.com/kangkyu/gdocs/blob/master/CHANGELOG.md"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
28
+ end
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ # Uncomment to register a new dependency of your gem
35
+ # spec.add_dependency "example-gem", "~> 1.0"
36
+
37
+ # For more information and examples about making a new gem, check out our
38
+ # guide at: https://bundler.io/guides/creating_gem.html
39
+ end
@@ -0,0 +1,44 @@
1
+ module Gdocs
2
+ # Provides methods to read and write config variables.
3
+ # Gdocs.configure do |config|
4
+ # config.client_id = '236011090214-lak27p8vsgi0lvi1endr21v2jhpljajc.apps.googleusercontent.com'
5
+ # config.client_secret = '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'
6
+ # end
7
+ #
8
+ # Note that Gdocs.configure has precedence over values through
9
+ # GDOCS_CLIENT_ID or GDOCS_CLIENT_SECRET environment variables.
10
+ #
11
+ module Config
12
+ # Yields the configuration to the given block.
13
+ #
14
+ # @yield [Gdocs::Configuration] The configuration.
15
+ def configure
16
+ yield configuration if block_given?
17
+ end
18
+
19
+ # Returns the {Gdocs::Configuration} object.
20
+ #
21
+ # @return [Gdocs::Configuration] The configuration.
22
+ def configuration
23
+ @configuration ||= Gdocs::Configuration.new
24
+ end
25
+ end
26
+
27
+ # @note in order to have a syntax as easy as Gdocs.configure
28
+ extend Config
29
+
30
+ class Configuration
31
+ # @return [String] the Client ID for Google clients.
32
+ # @see https://console.developers.google.com
33
+ attr_accessor :client_id
34
+
35
+ # @return [String] the Client Secret for Google clients.
36
+ # @see https://console.developers.google.com
37
+ attr_accessor :client_secret
38
+
39
+ def initialize
40
+ @client_id = ENV['GDOCS_CLIENT_ID']
41
+ @client_secret = ENV['GDOCS_CLIENT_SECRET']
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,60 @@
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ module Gdocs
5
+ module Models
6
+ class Document
7
+ attr_writer :data # for testing
8
+
9
+ def initialize
10
+ @data = {}
11
+ @token = ENV['GDOCS_AUTH_TOKEN']
12
+ end
13
+
14
+ def method_missing(m, *args, &block)
15
+ send(m, *args, &block) unless [:title, :document_id].include?(m)
16
+
17
+ # to_s.camelize(:lower) - if we have ActiveSupport as dependency
18
+ field = m.to_s.split('_').inject([]){ |buffer, e| buffer + [buffer.empty? ? e : e.capitalize] }.join
19
+ value = instance_variable_get("@#{m.to_s}") || instance_variable_set("@#{m.to_s}", @data[field])
20
+ value
21
+ end
22
+
23
+ # See https://developers.google.com/docs/api/reference/rest/v1/documents/get
24
+ def run_get(document_id)
25
+ return unless @token
26
+
27
+ uri_string = "https://docs.googleapis.com/v1/documents/#{document_id}"
28
+ url = URI uri_string
29
+
30
+ req = Net::HTTP::Get.new(uri_string)
31
+ req['Authorization'] = "Bearer #{@token}"
32
+
33
+ res = Net::HTTP.start(url.host, url.port, :use_ssl => url.scheme == 'https') do |http|
34
+ http.request(req)
35
+ end
36
+ @data.merge! JSON(res.body)
37
+ self
38
+ end
39
+
40
+ # See https://developers.google.com/docs/api/reference/rest/v1/documents/create
41
+ def run_create(options = {})
42
+ return unless @token
43
+
44
+ uri_string = "https://docs.googleapis.com/v1/documents"
45
+ url = URI uri_string
46
+
47
+ req = Net::HTTP::Post.new(uri_string)
48
+ req.initialize_http_header 'Content-Type' => 'application/json'
49
+ req['Authorization'] = "Bearer #{@token}"
50
+ req.body = {title: options[:title]}.to_json
51
+
52
+ res = Net::HTTP.start(url.host, url.port, :use_ssl => url.scheme == 'https') do |http|
53
+ http.request(req)
54
+ end
55
+ @data.merge! JSON(res.body)
56
+ self.document_id
57
+ end
58
+ end
59
+ end
60
+ end
data/lib/gdocs/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gdocs
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/gdocs.rb CHANGED
@@ -1,13 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "gdocs/version"
4
+ require "gdocs/config"
5
+ require "gdocs/models/document"
4
6
 
5
7
  module Gdocs
6
8
  class Error < StandardError; end
7
-
8
- class Hello
9
- def self.hello
10
- "Hello, world!"
11
- end
12
- end
9
+
13
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gdocs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kang-Kyu Lee
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-07 00:00:00.000000000 Z
11
+ date: 2022-10-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Generate or modify docs by API requests
14
14
  email:
@@ -22,7 +22,10 @@ files:
22
22
  - LICENSE.txt
23
23
  - README.md
24
24
  - Rakefile
25
+ - gdocs.gemspec
25
26
  - lib/gdocs.rb
27
+ - lib/gdocs/config.rb
28
+ - lib/gdocs/models/document.rb
26
29
  - lib/gdocs/version.rb
27
30
  - sig/gdocs.rbs
28
31
  homepage: https://rubygems.org/gems/gdocs