configly-ruby 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c22fd1c7b4856a9ad62ae8a870a40bbe447431c365a9a717faa512919e2fdce1
4
+ data.tar.gz: 1f1ea045a27b1dc8a5895b0d5f08054bfe0e9fdf15aae1c9759b21a3243ac0d6
5
+ SHA512:
6
+ metadata.gz: 13beb93697288800ff73e9d14f870c3c5071e82aaaae93ed72dbb0d21270e122040ba8f1fa025bff32317e5754500539cd6d4a5c04dcd37c3c2cb250f3976d00
7
+ data.tar.gz: 39050f72a4cc0a5705a705a92616f316d20945d5e6becf91057c8e2b9935e1a731271680c546399c8589e0c08fe23fff0797fc1f15963ad95e429d79aabf055d
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at dana11235@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in configly-ruby.gemspec
4
+ gemspec
@@ -0,0 +1,25 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ configly-ruby (0.0.1)
5
+ faye-websocket (~> 0.11)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ eventmachine (1.2.7)
11
+ faye-websocket (0.11.0)
12
+ eventmachine (>= 0.12.0)
13
+ websocket-driver (>= 0.5.1)
14
+ websocket-driver (0.7.3)
15
+ websocket-extensions (>= 0.1.0)
16
+ websocket-extensions (0.1.5)
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ configly-ruby!
23
+
24
+ BUNDLED WITH
25
+ 2.1.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Dana Levine
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,81 @@
1
+ # Configly React Library
2
+ > The Ruby library for [Configly](https://www.config.ly): the modern config/static data key/value store.
3
+
4
+ ![npm](https://img.shields.io/npm/v/configly-react)
5
+ ![GitHub](https://img.shields.io/github/license/configly/react)
6
+
7
+ Table of Contents
8
+ =================
9
+
10
+ * [What is Configly?](#what-is-configly)
11
+ * [Core Features](#core-features)
12
+ * [Getting Started](#getting-started)
13
+ * [Get your API Key](#get-your-api-key)
14
+ * [Library installation](#library-installation)
15
+ * [Usage](#usage)
16
+ * [Example](#example)
17
+ * [License](#license)
18
+
19
+
20
+ ## What is Configly?
21
+
22
+ [Configly](https://www.config.ly) is the place software developers put their static / config data—like
23
+ copy, styling, and minor configuration values.
24
+ They can then update that data directly from [https://www.config.ly](https://www.config.ly/)
25
+ without having to wait for a deploy process / app store review. Their app or webapp receives the data near instantly.
26
+ Non-technical folks themselves can publish changes freeing developers to focus on hard software problems and not copy tweaks.
27
+
28
+ On the backend, [Configly](https://www.config.ly) provides a read-optimized static-data key/value store built
29
+ with the aim of being low-latency, and high-availability. The client libraries are made to be dead-simple, lean, and efficient
30
+ (via enhancements like caching). There is a fancy [web UI called the Configulator](https://config.ly/config)
31
+ for setting and updating the configs as well as seeing things like change history. Configly is built for modern software development.
32
+
33
+ There are a host of other benefits to using Configly (
34
+ such as ensuring you do not have [data duplicated across clients](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself), reducing load on your primary DB, and better tolerance for traffic spikes),
35
+ read more about the benefits at [Configly](config.ly).
36
+
37
+ ### Core Features
38
+
39
+ - API to fetch Strings, JSON Blobs (arrays and objects), Booleans, and Numbers from the Configly backend
40
+ - [Web interface](https://www.config.ly/config) for modifying these values without having to deploy code (we call our beloved web interface _the Configulator_).
41
+ - High availability, high-throughput, low-latency backend.
42
+ - Smart caching on the client libraries to minimize server requests.
43
+ - Client libraries available in an expanding amount of languages.
44
+
45
+ ## Getting Started
46
+
47
+ ### Get your API Key
48
+
49
+ You'll need a [Configly](https://www.config.ly) account. Registration is lightning quick—you can register via
50
+ visiting [https://www.config.ly/signup](https://www.config.ly/signup).
51
+
52
+ After signing up, you can grab your API Key from [https://www.config.ly/register](https://www.config.ly/register).
53
+ You'll need your API Key to setup the API below.
54
+
55
+ ### Library installation
56
+
57
+ ```sh
58
+ gem install configly-ruby
59
+ ```
60
+
61
+ You will need to set the `CONFIGLY_API_KEY` environment variable.
62
+
63
+ If you want to use the optional websocket library, you can set:
64
+ ```
65
+ CONFIGLY_KEYS_TO_PRELOAD=test1,test2,test3 (these are the keys you want to use)
66
+ CONFIGLY_USE_WS=true
67
+ ```
68
+
69
+ ## Usage
70
+
71
+ To fetch a key, use the following command:
72
+
73
+ ```ruby
74
+ Configly::Client.get(KEY)
75
+ ```
76
+
77
+ If the key doesn't exist (or if you are using the websockets client and it hasn't been prefetched), this will rais a `Configly::KeyError`
78
+
79
+ ## License
80
+
81
+ This repository is published under the [MIT](LICENSE.md) license.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "configly/ruby"
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(__FILE__)
@@ -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
@@ -0,0 +1,19 @@
1
+ $LOAD_PATH.push File.expand_path("lib", __dir__)
2
+ require_relative 'lib/configly/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'configly-ruby'
6
+ s.version = '0.0.2'
7
+ s.date = '2020-11-15'
8
+ s.summary = "Configly"
9
+ s.description = "Configly SDK gem"
10
+ s.authors = ["Dana Levine"]
11
+ s.email = 'dana11235@gmail.com'
12
+ s.files = `git ls-files -z`.split("\x0")
13
+ s.homepage = 'https://rubygems.org/gems/configly'
14
+ s.license = 'MIT'
15
+
16
+ s.add_runtime_dependency 'faye-websocket', '~> 0.11'
17
+
18
+ s.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,105 @@
1
+ require 'net/http'
2
+ require 'faye/websocket'
3
+ require 'eventmachine'
4
+
5
+ CONFIGLY_SERVER = 'api.config.ly'
6
+ CONFIGLY_VALUE_URL = '/api/v1/value'
7
+
8
+ module Configly
9
+ class Client
10
+ @keys = {}
11
+ @caches = {}
12
+ @use_ws = false
13
+ def self.init
14
+ @use_ws = true
15
+ if get_api_key
16
+ load_initial_data
17
+ Thread.new { EM.run { start_web_socket_client }}
18
+ end
19
+ end
20
+
21
+ def self.get_api_key
22
+ return ENV['CONFIGLY_API_KEY']
23
+ end
24
+
25
+ def self.get_keys_to_preload
26
+ return ENV['CONFIGLY_KEYS_TO_PRELOAD'].split(',')
27
+ end
28
+
29
+ def self.generate_qs(keys_to_preload)
30
+ return keys_to_preload.map { |key| "keys[]=#{key}" }.join("&")
31
+ end
32
+
33
+ def self.load_initial_data
34
+ @keys = fetch(get_keys_to_preload)
35
+ end
36
+
37
+ def self.start_web_socket_client
38
+ ws = Faye::WebSocket::Client.new("ws://configly.herokuapp.com", nil, {:ping => 30})
39
+
40
+ ws.on :open do |event|
41
+ Rails.logger.debug :open
42
+ ws.send(JSON.generate({"apiKey" => get_api_key, "type" => "handshake"}))
43
+ end
44
+
45
+ ws.on :message do |event|
46
+ Rails.logger.debug :message
47
+ data = JSON.parse(event.data)
48
+ if data["type"] == "configUpdate"
49
+ payload = data["payload"]["payload"]
50
+ keyToUpdate = payload['key']
51
+ value = payload['value']
52
+ @keys[keyToUpdate] = value
53
+ end
54
+
55
+ Rails.logger.debug @keys
56
+ end
57
+
58
+ ws.on :close do |event|
59
+ Rails.logger.debug :close
60
+ Rails.logger.debug event.code
61
+ start_web_socket_client
62
+ end
63
+ end
64
+
65
+ def self.fetch(keys)
66
+ uri = URI("https://#{CONFIGLY_SERVER}#{CONFIGLY_VALUE_URL}?#{generate_qs(keys)}")
67
+ loaded_keys = {}
68
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
69
+ request = Net::HTTP::Get.new uri
70
+ request.basic_auth get_api_key, ''
71
+ response = http.request request
72
+ print "\n#{response.code}\n"
73
+ print "\n#{response.body}\n"
74
+ data = JSON.parse(response.body)['data']
75
+ data.keys.each do |key|
76
+ loaded_keys[key] = data[key]['value']
77
+ end
78
+ end
79
+ return loaded_keys
80
+ end
81
+
82
+ def self.get(key)
83
+ if @use_ws
84
+ if @keys.has_key? key
85
+ return @keys[key]
86
+ else
87
+ raise KeyError.new(key)
88
+ end
89
+ else
90
+ loaded_keys = fetch([key])
91
+ if loaded_keys.has_key? key
92
+ return[key]
93
+ else
94
+ raise KeyError.new(key)
95
+ end
96
+ end
97
+ end
98
+ end
99
+
100
+ class KeyError < KeyError
101
+ def initialize(key)
102
+ super(key)
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,9 @@
1
+ module Configly
2
+ class Railtie < Rails::Railtie
3
+ config.after_initialize do
4
+ if ENV['CONFIGLY_USE_WS']
5
+ Client.init
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ require 'configly/client'
2
+ require 'configly/railtie'
3
+ require 'configly/version'
@@ -0,0 +1,3 @@
1
+ module Configly
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,9 @@
1
+ RSpec.describe Configly::Ruby do
2
+ it "has a version number" do
3
+ expect(Configly::Ruby::VERSION).not_to be nil
4
+ end
5
+
6
+ it "does something useful" do
7
+ expect(false).to eq(true)
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ require "bundler/setup"
2
+ require "configly/ruby"
3
+
4
+ RSpec.configure do |config|
5
+ # Enable flags like --only-failures and --next-failure
6
+ config.example_status_persistence_file_path = ".rspec_status"
7
+
8
+ # Disable RSpec exposing methods globally on `Module` and `main`
9
+ config.disable_monkey_patching!
10
+
11
+ config.expect_with :rspec do |c|
12
+ c.syntax = :expect
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: configly-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Dana Levine
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-11-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faye-websocket
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.11'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.11'
27
+ description: Configly SDK gem
28
+ email: dana11235@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - ".gitignore"
34
+ - ".rspec"
35
+ - ".travis.yml"
36
+ - CODE_OF_CONDUCT.md
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - bin/console
43
+ - bin/setup
44
+ - configly-ruby.gemspec
45
+ - lib/configly/client.rb
46
+ - lib/configly/railtie.rb
47
+ - lib/configly/ruby.rb
48
+ - lib/configly/version.rb
49
+ - spec/configly/ruby_spec.rb
50
+ - spec/spec_helper.rb
51
+ homepage: https://rubygems.org/gems/configly
52
+ licenses:
53
+ - MIT
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.1.2
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Configly
74
+ test_files: []