cloudflare_storage 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: cb0947aadcd4d5569d1b7dfc86ac2b10d30510d26532150cff86fe1a82edce00
4
- data.tar.gz: 9ed75b05b6492d1a7519d877fec5760adc0727917363765604b1c057d4779d26
3
+ metadata.gz: 7a27accd4b03e06ab2c373bb7617c70ca2c50fc0bd87de804fcb0c87421b3807
4
+ data.tar.gz: f1f6c982dd6526ed2b8ac2a01cff6b6fd455efdde0f09508f8ee11dee72f2ee1
5
5
  SHA512:
6
- metadata.gz: 9903d4d58316ac04a30099b49e08d224fd9d7a4282eb897880300d5cae37712c0ce8c2cac91a5ac5a6344a3f1961e7276ef7389e3b0639e45d2bf218b5cfcef1
7
- data.tar.gz: 5ad630b82c75ba55f3b61329acff25a853bcab4c2afbe736a9ef7f0cfe47097f9a3c30f0957451fbab9cadc8b593cc215653eac33696a2b0934707baa2c207ff
6
+ metadata.gz: 5b134c933de2c1b2ef28ef8e7b9ea1ed27398a3d4f870bec36e504a65a06ffc4a8dc4ab63f486ab0855fd51b1b06a884b1d72555043811f7a32e99bb0628de90
7
+ data.tar.gz: 2da298abe14850668727c66766420b5ae32181a9ff2b61015b2ce9316a8965e8d7542c4e7465adca8aea9b297b41b54f0ac20d2e2d88b70a14042641ea555d94
data/README.md CHANGED
@@ -6,11 +6,9 @@ It was designed to let you get started with minimal configuration.
6
6
 
7
7
  ## Installation
8
8
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
-
11
9
  Add this line to your application's Gemfile:
12
10
 
13
- ````
11
+ ```
14
12
  gem 'cloudflare_storage'
15
13
  ```
16
14
 
@@ -0,0 +1,44 @@
1
+ require 'faraday'
2
+ module CloudflareStorage
3
+ class Client
4
+ def initialize(account_id, namespace_id, token, connection = nil)
5
+ raise MissingCredentialsError, "Please configure account_id" if account_id.nil?
6
+ raise MissingCredentialsError, "Please configure namespace_id" if namespace_id.nil?
7
+ raise MissingCredentialsError, "Please configure token" if token.nil?
8
+
9
+ @conn = connection || Faraday.new(url: "https://api.cloudflare.com/client/v4/accounts/#{account_id}/storage/kv/namespaces/#{namespace_id}/" ) do |builder|
10
+ builder.request :authorization, "Bearer", token
11
+ builder.request :json
12
+ builder.response :json
13
+ builder.response :raise_error
14
+ end
15
+ end
16
+
17
+ def values
18
+ @values ||= Values.new(self)
19
+ end
20
+
21
+ def keys
22
+ @keys ||= Keys.new(self)
23
+ end
24
+
25
+ protected
26
+ def get(path, params = nil)
27
+ puts "Getting"
28
+ puts "Connection #{@conn}"
29
+ @conn.get path do |req|
30
+ req.params = params if params && !params.empty?
31
+ end
32
+ end
33
+
34
+ def put(path, body)
35
+ @conn.put path do |req|
36
+ req.body = body
37
+ end
38
+ end
39
+
40
+ def conn_delete(path)
41
+ @conn.delete path
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,7 @@
1
+ module CloudflareStorage
2
+ class Error < StandardError
3
+ end
4
+
5
+ class MissingCredentialsError < Error
6
+ end
7
+ end
@@ -1,4 +1,4 @@
1
- module WorkersKV
1
+ module CloudflareStorage
2
2
  class Keys < Client
3
3
 
4
4
  def initialize(client)
@@ -6,7 +6,7 @@ module WorkersKV
6
6
  end
7
7
 
8
8
  def list(prefix)
9
- if prefix.present?
9
+ if prefix && !prefix.empty?
10
10
  @client.get("keys", { "prefix": prefix })
11
11
  else
12
12
  @client.get("keys")
@@ -1,8 +1,8 @@
1
- module WorkersKV
1
+ module CloudflareStorage
2
2
  class Values < Client
3
3
 
4
4
  def initialize(client)
5
- @client = client
5
+ @client ||= client
6
6
  end
7
7
 
8
8
  # Manage Values
@@ -0,0 +1,3 @@
1
+ module CloudflareStorage
2
+ VERSION = '0.1.1'
3
+ end
@@ -1,43 +1,52 @@
1
1
  # frozen_string_literal: true
2
- require_relative "workers_kv/client"
3
- require_relative "workers_kv/values"
4
- require_relative "workers_kv/keys"
2
+ require_relative "cloudflare_storage/client"
3
+ require_relative "cloudflare_storage/values"
4
+ require_relative "cloudflare_storage/keys"
5
+ require_relative "cloudflare_storage/version"
6
+ require_relative "cloudflare_storage/error"
5
7
 
6
8
 
7
- class CloudflareStorage
9
+ module CloudflareStorage
8
10
  class << self
9
- attr_accessor :account_id, :namespace_id, :token
11
+ attr_accessor :configuration
12
+
13
+ def configure(&block)
14
+ self.configuration ||= Configuration.new
15
+ yield(configuration)
16
+ end
17
+
18
+ def conn
19
+ raise MissingCredentialsError, "CloudflareStorage not configured" if CloudflareStorage.configuration.nil?
20
+ @connection ||= Client.new(
21
+ CloudflareStorage.configuration.account_id,
22
+ CloudflareStorage.configuration.namespace_id,
23
+ CloudflareStorage.configuration.token,
24
+ CloudflareStorage.configuration.connection
25
+ )
26
+ end
27
+
28
+ def list(prefix = nil)
29
+ resp = conn.keys.list(prefix)
30
+ resp.body.dig("result").pluck("name")
31
+ end
32
+
33
+ def read(key)
34
+ resp = conn.values.read(key)
35
+ resp.body
36
+ end
37
+
38
+ def write(key, value)
39
+ resp = conn.values.write(key, value)
40
+ resp.body
41
+ end
42
+
43
+ def delete(key)
44
+ resp = conn.values.delete(key)
45
+ resp.body
46
+ end
10
47
  end
11
48
 
12
- def self.configure(&block)
13
- yield self
14
- end
15
-
16
- def conn
17
- @connection ||= WorkersKV::Client.new(
18
- CloudflareStorage.account_id,
19
- CloudflareStorage.namespace_id,
20
- CloudflareStorage.token
21
- )
22
- end
23
-
24
- def list(prefix = nil)
25
- resp = conn.keys.list(prefix)
26
- resp.body.dig("result").pluck("name")
27
- end
28
-
29
- def read(key)
30
- resp = conn.values.read(key)
31
- resp.body
32
- end
33
-
34
- def write(key, value)
35
- resp = conn.values.write(key, value)
36
- resp.body
37
- end
38
-
39
- def delete(key)
40
- resp = conn.values.delete(key)
41
- resp.body
49
+ class Configuration
50
+ attr_accessor :account_id, :namespace_id, :token, :connection
42
51
  end
43
52
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudflare_storage
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
- - Lee Gillentine
7
+ - "@geetotes"
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-02-04 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2025-02-10 00:00:00.000000000 Z
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: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
13
27
  description: Library for interacting with Cloudflare Workers KV Storage and configuring
14
28
  connection from a Rails application.
15
29
  email:
@@ -24,9 +38,11 @@ files:
24
38
  - README.md
25
39
  - Rakefile
26
40
  - lib/cloudflare_storage.rb
27
- - lib/workers_kv/client.rb
28
- - lib/workers_kv/keys.rb
29
- - lib/workers_kv/values.rb
41
+ - lib/cloudflare_storage/client.rb
42
+ - lib/cloudflare_storage/error.rb
43
+ - lib/cloudflare_storage/keys.rb
44
+ - lib/cloudflare_storage/values.rb
45
+ - lib/cloudflare_storage/version.rb
30
46
  - sig/cloudflare_storage.rbs
31
47
  homepage: https://github.com/geetotes/cloudflare_storage
32
48
  licenses:
@@ -1,37 +0,0 @@
1
- module WorkersKV
2
- class Client
3
- def initialize(account_id, namespace_id, token)
4
- @conn = Faraday.new(url: "https://api.cloudflare.com/client/v4/accounts/#{account_id}/storage/kv/namespaces/#{namespace_id}/" ) do |builder|
5
- builder.request :authorization, "Bearer", token
6
- builder.request :json
7
- builder.response :json
8
- builder.response :raise_error
9
- end
10
- end
11
-
12
- def values
13
- @values ||= Values.new(self)
14
- end
15
-
16
- def keys
17
- @keys ||= Keys.new(self)
18
- end
19
-
20
- protected
21
- def get(path, params = nil)
22
- @conn.get path do |req|
23
- req.params = params if params.present?
24
- end
25
- end
26
-
27
- def put(path, body)
28
- @conn.put path do |req|
29
- req.body = body
30
- end
31
- end
32
-
33
- def conn_delete(path)
34
- @conn.delete path
35
- end
36
- end
37
- end