cloudflair 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f7b07b6a0fac5738b738c9297a932f101e3dc78
4
- data.tar.gz: 4aaead028eefb8c1d2bdbe95bfc14f02076de102
3
+ metadata.gz: 6af6e2d4ab47ef06e9cae85280c935cf7ccd30fe
4
+ data.tar.gz: e2bbcb00bd5a0d93713e16f02c29a6ff73737e35
5
5
  SHA512:
6
- metadata.gz: 46d9cbe6c1f217fc1cfbaa781340ab568653b00cd8fe0de0fbc43af9d235fb77495899772a8544e97af29f02781e8c77a47a70956f3c93cba115cf40a5d4e907
7
- data.tar.gz: f24eda1248e1c86f68980f9eb08c83b06a676739cf47493207f9af999a6762d7a92276e569aa9c5e9d3f9cf1ad609d0dd23da7b14669f829b1288138a67b4279
6
+ metadata.gz: cd498ded8ec3fb1093dd554063b5f79514e866a792beda3b27d401ced0e1b4d23f9f48f2c2742907902e5e4c2eeb53bf95f14bf0df99f1989f88b375afb67928
7
+ data.tar.gz: 73658e1f85c007d0ab71f55c2d83f84e0d51ef7df4f52e99bd0815653b5d6ea82c0ee3586914bcf4865756ef4f6ae9d0a3be3e2a80cd5bf07b2835e3cc7fe2f3
data/README.md CHANGED
@@ -48,7 +48,7 @@ end
48
48
 
49
49
  ### Call An API Endpoint
50
50
 
51
- This gem is organized along the URL schema of cloudflair.
51
+ This gem is organized along the URL schema of CloudFlare.
52
52
 
53
53
  ```ruby
54
54
  require 'cloudflair'
data/cloudflair.gemspec CHANGED
@@ -21,12 +21,11 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = %w(lib)
23
23
 
24
- spec.add_runtime_dependency 'faraday', ['~> 0.8.11']
25
- spec.add_runtime_dependency 'faraday_middleware', ['~> 0.10.0']
26
- spec.add_runtime_dependency 'dry-configurable', ['~> 0.1.7']
24
+ spec.add_runtime_dependency 'faraday', '~> 0.9.0'
25
+ spec.add_runtime_dependency 'faraday_middleware', '~> 0.10.0'
26
+ spec.add_runtime_dependency 'dry-configurable', '~> 0.1'
27
27
 
28
28
  spec.add_development_dependency 'bundler', '~> 1.12'
29
29
  spec.add_development_dependency 'rake', '~> 10.0'
30
30
  spec.add_development_dependency 'rspec', '~> 3.0'
31
- spec.add_development_dependency 'rubocop', '~> 0.44.1'
32
31
  end
@@ -0,0 +1,27 @@
1
+ require 'cloudflair/communication'
2
+
3
+ module Cloudflair
4
+ class PurgeCache
5
+ attr_reader :zone_id
6
+
7
+ include Cloudflair::Communication
8
+
9
+ def initialize(zone_id)
10
+ @zone_id = zone_id
11
+ end
12
+
13
+ def purge_all_files(purge_everything=false)
14
+
15
+ end
16
+
17
+ ##
18
+ # @param [Hash] cache_identifier Consists of :files and :tags, which are String Arrays themselves. Sample: <code>{files: ['https://foo.bar/index.htmll'], tags: ['css','js']}
19
+ def purge(cache_identifier = {})
20
+
21
+ end
22
+
23
+ def connection
24
+ Connection.new
25
+ end
26
+ end
27
+ end
@@ -1,19 +1,21 @@
1
- require 'cloudflair/communication'
1
+ require 'cloudflair/entity'
2
2
 
3
3
  module Cloudflair
4
4
  class DevelopmentMode
5
- include Cloudflair::Communication
5
+ include Cloudflair::Entity
6
6
 
7
7
  attr_accessor :zone_id
8
8
 
9
9
  patchable_fields :value
10
10
 
11
- def path
12
- "/zones/#{zone_id}/settings/development_mode"
13
- end
14
-
15
11
  def initialize(zone_id)
16
12
  @zone_id = zone_id
17
13
  end
14
+
15
+ private
16
+
17
+ def path
18
+ "zones/#{zone_id}/settings/development_mode"
19
+ end
18
20
  end
19
21
  end
@@ -1,5 +1,5 @@
1
1
  require 'cloudflair/api/zone/settings'
2
- require 'cloudflair/communication'
2
+ require 'cloudflair/entity'
3
3
 
4
4
  module Cloudflair
5
5
  def self.zone(zone_id)
@@ -7,11 +7,12 @@ module Cloudflair
7
7
  end
8
8
 
9
9
  class Zone
10
- include Cloudflair::Communication
10
+ include Cloudflair::Entity
11
11
 
12
12
  attr_reader :zone_id
13
13
 
14
14
  patchable_fields :paused, :vanity_name_servers, :plan
15
+ deletable true
15
16
 
16
17
  def initialize(zone_id)
17
18
  @zone_id = zone_id
@@ -24,7 +25,7 @@ module Cloudflair
24
25
  private
25
26
 
26
27
  def path
27
- "/zones/#{zone_id}"
28
+ "zones/#{zone_id}"
28
29
  end
29
30
  end
30
31
  end
@@ -4,110 +4,6 @@ require 'cloudflair/connection'
4
4
 
5
5
  module Cloudflair
6
6
  module Communication
7
- def self.included(other_klass)
8
- other_klass.extend ClassMethods
9
- end
10
-
11
- module ClassMethods
12
- def patchable_fields(*fields)
13
- return @patchable_fields if @patchable_fields
14
-
15
- if fields.nil?
16
- @patchable_fields = []
17
- elsif fields.is_a?(Array)
18
- @patchable_fields = fields.map(&:to_s)
19
- else
20
- @patchable_fields = [fields.to_s]
21
- end
22
- end
23
- end
24
-
25
- def revert
26
- dirty.clear
27
- end
28
-
29
- def reload
30
- @data = get
31
- revert
32
- self
33
- end
34
-
35
- def patch
36
- return self if dirty.empty?
37
-
38
- @data = response connection.patch path, dirty
39
- revert
40
- self
41
- end
42
-
43
- def update(updated_fields)
44
- checked_updated_fields = {}
45
- updated_fields.each do |key, values|
46
- s_key = normalize_accessor key
47
-
48
- checked_updated_fields[s_key] = values if patchable_fields.include? s_key
49
- end
50
-
51
- dirty.merge! checked_updated_fields
52
- patch
53
- end
54
-
55
- def method_missing(name_as_symbol, *args, &block)
56
- name = normalize_accessor name_as_symbol
57
-
58
- if name.end_with?('=')
59
- if patchable_fields.include?(name[0..-2])
60
- dirty[name[0..-2]] = args[0]
61
- return
62
- else
63
- super
64
- end
65
- end
66
-
67
- # allow access to the original data using 'zone.always_string!' or 'zone._name!'
68
- if name.end_with?('!') && data.keys.include?(name[0..-2])
69
- return data[name[0..2]]
70
- end
71
-
72
- return dirty[name] if dirty.keys.include? name
73
- return data[name] if data.keys.include? name
74
-
75
- super
76
- end
77
-
78
- def respond_to_missing?(name_as_symbol, *args)
79
- name = normalize_accessor name_as_symbol
80
-
81
- return true if name.end_with?('=') && patchable_fields.include?(name[0..-2])
82
- return true if name.end_with?('!') && data.keys.include?(name[0..-2])
83
-
84
- return true if dirty.keys.include? name
85
- return true if data.keys.include? name
86
-
87
- super
88
- end
89
-
90
- alias get! reload
91
- alias save patch
92
-
93
- private
94
-
95
- def normalize_accessor(symbol_or_string)
96
- always_string = symbol_or_string.to_s
97
-
98
- # allows access to remote data who's name conflicts with pre-defined methods
99
- # e.g. write 'zone._zone_id' instead of 'zone.zone_id' to access the remote value of 'zone_id'
100
- always_string.start_with?('_') ? always_string[1..-1] : always_string
101
- end
102
-
103
- def data
104
- @data ||= get
105
- end
106
-
107
- def get
108
- response connection.get path
109
- end
110
-
111
7
  def response(response)
112
8
  body = response.body
113
9
 
@@ -119,16 +15,8 @@ module Cloudflair
119
15
  body['result']
120
16
  end
121
17
 
122
- def dirty
123
- @dirty ||= {}
124
- end
125
-
126
18
  def connection
127
- Connection.new
128
- end
129
-
130
- def patchable_fields
131
- self.class.patchable_fields
19
+ Cloudflair::Connection.new
132
20
  end
133
21
  end
134
22
  end
@@ -1,25 +1,27 @@
1
- class Connection
2
- def self.new
3
- config = Cloudflair.config
1
+ module Cloudflair
2
+ class Connection
3
+ def self.new
4
+ config = Cloudflair.config
4
5
 
5
- Faraday.new(url: config.cloudflare.api_base_url, headers: headers) do |faraday|
6
- faraday.request :url_encoded
7
- faraday.response :logger
8
- faraday.response :json, content_type: /\bjson$/
6
+ Faraday.new(url: config.cloudflare.api_base_url, headers: headers) do |faraday|
7
+ faraday.request :url_encoded
8
+ faraday.response :logger
9
+ faraday.response :json, content_type: /\bjson$/
9
10
 
10
- faraday.adapter config.faraday.adapter || Faraday.default_adapter
11
+ faraday.adapter config.faraday.adapter || Faraday.default_adapter
12
+ end
11
13
  end
12
- end
13
14
 
14
- def self.headers
15
- headers = {}
16
- cloudflare_auth_config = Cloudflair.config.cloudflare.auth
17
- if cloudflare_auth_config.user_service_key.nil?
18
- headers['X-Auth-Key'] = cloudflare_auth_config.key
19
- headers['X-Auth-Email'] = cloudflare_auth_config.email
20
- else
21
- headers['X-Auth-User-Service-Key'] = cloudflare_auth_config.user_service_key
15
+ def self.headers
16
+ headers = {}
17
+ cloudflare_auth_config = Cloudflair.config.cloudflare.auth
18
+ if cloudflare_auth_config.user_service_key.nil?
19
+ headers['X-Auth-Key'] = cloudflare_auth_config.key
20
+ headers['X-Auth-Email'] = cloudflare_auth_config.email
21
+ else
22
+ headers['X-Auth-User-Service-Key'] = cloudflare_auth_config.user_service_key
23
+ end
24
+ headers
22
25
  end
23
- headers
24
26
  end
25
27
  end
@@ -0,0 +1,139 @@
1
+ require 'cloudflair/communication'
2
+
3
+ module Cloudflair
4
+ module Entity
5
+ include Cloudflair::Communication
6
+
7
+ def self.included(other_klass)
8
+ other_klass.extend ClassMethods
9
+ end
10
+
11
+ module ClassMethods
12
+ def patchable_fields(*fields)
13
+ return @patchable_fields if @patchable_fields
14
+
15
+ if fields.nil?
16
+ @patchable_fields = []
17
+ elsif fields.is_a?(Array)
18
+ @patchable_fields = fields.map(&:to_s)
19
+ else
20
+ @patchable_fields = [fields.to_s]
21
+ end
22
+ end
23
+
24
+ def deletable(deletable = false)
25
+ return @deletable unless @deletable.nil?
26
+
27
+ @deletable = deletable
28
+ end
29
+ end
30
+
31
+ def revert
32
+ dirty.clear
33
+ end
34
+
35
+ def reload
36
+ @data = get
37
+ revert
38
+ self
39
+ end
40
+
41
+ def patch
42
+ return self if dirty.empty?
43
+
44
+ @data = response connection.patch path, dirty
45
+ revert
46
+ self
47
+ end
48
+
49
+ def delete
50
+ fail Cloudflair::CloudflairError, "Can't delete unless deletable=true" unless deletable
51
+ return self if @deleted
52
+
53
+ @data = response connection.delete path
54
+ @deleted = true
55
+ revert
56
+ self
57
+ end
58
+
59
+ def update(updated_fields)
60
+ checked_updated_fields = {}
61
+ updated_fields.each do |key, values|
62
+ s_key = normalize_accessor key
63
+
64
+ checked_updated_fields[s_key] = values if patchable_fields.include? s_key
65
+ end
66
+
67
+ dirty.merge! checked_updated_fields
68
+ patch
69
+ end
70
+
71
+ def method_missing(name_as_symbol, *args, &block)
72
+ name = normalize_accessor name_as_symbol
73
+
74
+ if name.end_with?('=')
75
+ if patchable_fields.include?(name[0..-2])
76
+ dirty[name[0..-2]] = args[0]
77
+ return
78
+ else
79
+ super
80
+ end
81
+ end
82
+
83
+ # allow access to the original data using 'zone.always_string!' or 'zone._name!'
84
+ if name.end_with?('!') && data.keys.include?(name[0..-2])
85
+ return data[name[0..2]]
86
+ end
87
+
88
+ return dirty[name] if dirty.keys.include? name
89
+ return data[name] if data.keys.include? name
90
+
91
+ super
92
+ end
93
+
94
+ def respond_to_missing?(name_as_symbol, *args)
95
+ name = normalize_accessor name_as_symbol
96
+
97
+ return true if name.end_with?('=') && patchable_fields.include?(name[0..-2])
98
+ return true if name.end_with?('!') && data.keys.include?(name[0..-2])
99
+
100
+ return true if dirty.keys.include? name
101
+ return true if data.keys.include? name
102
+
103
+ super
104
+ end
105
+
106
+ alias get! reload
107
+ alias save patch
108
+
109
+ private
110
+
111
+ def normalize_accessor(symbol_or_string)
112
+ always_string = symbol_or_string.to_s
113
+
114
+ # allows access to remote data who's name conflicts with pre-defined methods
115
+ # e.g. write 'zone._zone_id' instead of 'zone.zone_id' to access the remote value of 'zone_id'
116
+ always_string.start_with?('_') ? always_string[1..-1] : always_string
117
+ end
118
+
119
+ def data
120
+ @data ||= get
121
+ end
122
+
123
+ def get
124
+ response connection.get path
125
+ end
126
+
127
+ def patchable_fields
128
+ self.class.patchable_fields
129
+ end
130
+
131
+ def deletable
132
+ self.class.deletable
133
+ end
134
+
135
+ def dirty
136
+ @dirty ||= {}
137
+ end
138
+ end
139
+ end
@@ -1,3 +1,3 @@
1
1
  module Cloudflair
2
- VERSION = '0.0.2'.freeze
2
+ VERSION = '0.0.3'.freeze
3
3
  end
data/lib/cloudflair.rb CHANGED
@@ -24,7 +24,7 @@ module Cloudflair
24
24
  extend Dry::Configurable
25
25
 
26
26
  setting :cloudflare do
27
- setting :api_base_url, 'https://api.cloudflare.com'
27
+ setting :api_base_url, 'https://api.cloudflare.com/client/v4/'
28
28
  setting :auth do
29
29
  setting :key
30
30
  setting :email
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudflair
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Mäder
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-19 00:00:00.000000000 Z
11
+ date: 2016-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.8.11
19
+ version: 0.9.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.8.11
26
+ version: 0.9.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: faraday_middleware
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.1.7
47
+ version: '0.1'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.1.7
54
+ version: '0.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -94,20 +94,6 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '3.0'
97
- - !ruby/object:Gem::Dependency
98
- name: rubocop
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: 0.44.1
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: 0.44.1
111
97
  description: Cloudflair aims to provide easy access to CloudFlares public API.
112
98
  email:
113
99
  - christian.maeder@nine.ch
@@ -128,10 +114,12 @@ files:
128
114
  - cloudflair.gemspec
129
115
  - lib/cloudflair.rb
130
116
  - lib/cloudflair/api/zone.rb
117
+ - lib/cloudflair/api/zone/purge_cache.rb
131
118
  - lib/cloudflair/api/zone/settings.rb
132
119
  - lib/cloudflair/api/zone/settings/development_mode.rb
133
120
  - lib/cloudflair/communication.rb
134
121
  - lib/cloudflair/connection.rb
122
+ - lib/cloudflair/entity.rb
135
123
  - lib/cloudflair/error/cloudflair_error.rb
136
124
  - lib/cloudflair/error/cloudflare_error.rb
137
125
  - lib/cloudflair/version.rb