NCCConfidence 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 15bd4eee7c38cd51ec5f67a545e7b6b86584d42a
4
+ data.tar.gz: 3462ffd9f597041ac600d710f15634856c69e08a
5
+ SHA512:
6
+ metadata.gz: 7ff2ea11db2917d36f4875f378514663c8c262e77cbe63d007d94bfeac394f23b235605428f8cd2ae5d7cd282537e2a240b2a2fa9cd93eb37e23cc7352315d3c
7
+ data.tar.gz: 8f3e9f2f30719e3cc6806c77042efa0adff3d1d636f851ba4bce6be365c4f3e15d446ab5eb14868440d0f57f11c0b9b03d963a358492e275f57c87b709088eea
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ test*
11
+ /test
12
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in NCCConfidence.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Thermatix
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,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'nccconfidence/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "NCCConfidence"
8
+ spec.version = NCCConfidence::VERSION
9
+ spec.authors = ["Thermatix"]
10
+ spec.email = ["mbeckerwork@gmail.com"]
11
+
12
+ spec.summary = %q{This is a gem to make queries to NCC Site confidence API}
13
+ spec.homepage = "https://github.com/Thermatix/NCCConfidence_API"
14
+ spec.license = "MIT"
15
+
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "addressable" , "2.3.8"
23
+ spec.add_runtime_dependency "curb" , "0.88"
24
+ spec.add_runtime_dependency "json" , "1.8.3"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.9"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ end
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # NCCConfidence
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/NCCConfidence`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'NCCConfidence'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install NCCConfidence
22
+
23
+ ## Usage
24
+ ```ruby
25
+ data_filter = [
26
+ {
27
+ book: [
28
+ { pages:[
29
+ :page_number,
30
+ {page_meta:
31
+ [
32
+ :description,
33
+ :author,
34
+ :page_name
35
+ ]
36
+ }
37
+ ]
38
+ }
39
+ ]
40
+ }
41
+ ]
42
+
43
+ build(f)
44
+ #=>[book[pages[page_number,page_meta[description,author,page_name]]]]
45
+ ```
46
+
47
+ ## Development
48
+
49
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
50
+
51
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
52
+
53
+ ## Contributing
54
+
55
+ 1. Fork it ( https://github.com/[my-github-username]/NCCConfidence/fork )
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "NCCConfidence"
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,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+ module NCCConfidence
2
+ module Builder
3
+ class Data
4
+ attr_reader :attributes
5
+
6
+ class << self
7
+ def make &script
8
+ t = self.new
9
+ t.instance_eval(&script)
10
+ t.attributes
11
+ end
12
+ end
13
+
14
+ def initialize
15
+ @attributes = []
16
+ end
17
+
18
+ def item value
19
+ @attributes << value
20
+ end
21
+
22
+ def object key, &value
23
+ @attributes << {key => self.class.make(&value)}
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,24 @@
1
+ #takes in return filters as a hash and returns a data-filter string
2
+ module NCCConfidence
3
+ class D_Filters
4
+ class << self
5
+ def build filter_object
6
+ "[#{make_filter(filter_object)}]"
7
+ end
8
+
9
+ def make_filter items
10
+ items.map do |item|
11
+ if item.class == Hash
12
+ item.each do |key,value|
13
+ break "#{key.to_s}[#{make_filter(value)}]"
14
+ end
15
+ else
16
+ item.to_s #ensures symbols are correctly formated if and when used
17
+ end
18
+ end.join(',')
19
+ end
20
+
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,87 @@
1
+ require "curb"
2
+
3
+ module NCCConfidence
4
+ class Http
5
+ class << self
6
+
7
+
8
+ def request &scipt
9
+ t = self.new
10
+ t.instance_eval(&scipt)
11
+ t
12
+ end
13
+
14
+ end
15
+ attr_accessor :curl, :headers,:payload, :username, :password, :auth_type, :uri, :ssl, :redirects
16
+ [:get, :post, :put, :delete, :head, :options, :patch, :link, :unlink].each do |func_name|
17
+ define_method func_name do
18
+ make_request_of func_name.to_s.upcase
19
+ end
20
+ end
21
+
22
+ def initialize
23
+ self.headers = {}
24
+ end
25
+
26
+ def header name, content
27
+ self.headers[name] = content
28
+ end
29
+
30
+ [:set_password,:set_username,:set_payload, :set_auth_type, :set_uri, :set_ssl, :set_redirects].each do |func_name|
31
+ define_method func_name do |value|
32
+ self.send("#{func_name.to_s.gsub('set_','')}=",value)
33
+ end
34
+ end
35
+
36
+ def make_request_of (request_method)
37
+ self.curl = Curl::Easy.new(self.uri) do |http|
38
+ setup_request request_method, http
39
+ end
40
+ self.curl.ssl_verify_peer = self.ssl ||false
41
+ self.curl.http request_method
42
+ if self.curl.response_code == 301
43
+ self.uri = self.curl.redirect_url
44
+ make_request_of request_method
45
+ end
46
+ end
47
+
48
+ def response
49
+ self.curl.response_code
50
+ end
51
+
52
+ def body
53
+ self.curl.body_str
54
+ end
55
+
56
+ def setup_request method,http
57
+ http.headers['request-method'] = method.to_s
58
+ http.headers.update(headers)
59
+ http.max_redirects = self.redirects || 3
60
+ http.post_body = self.payload || nil
61
+ http.http_auth_types = self.auth_type || nil
62
+ http.username = self.username || nil
63
+ http.password = self.password || nil
64
+ http.useragent = "curb"
65
+ http
66
+ end
67
+
68
+ # def self.get url, keys
69
+ # Curl::Easy.perform(url) do |curl|
70
+ # curl.headers["User-Agent"] = "#{VCK::Info[:name]}-#{VCK::Info[:version]}"
71
+ # end.body_str
72
+ # end
73
+
74
+ # def self.post data,url
75
+ # headers ={
76
+ # 'Content-Type' => 'application/json',
77
+ # 'X-Requested-With' => 'XMLHttpRequest',
78
+ # 'Accept' => 'application/json'
79
+ # }
80
+ # client = Curl::Easy.new
81
+ # client.url = url
82
+ # client.headers = headers
83
+ # client.http_post(payload)
84
+
85
+ # end
86
+ end
87
+ end
@@ -0,0 +1,22 @@
1
+ require "addressable/uri"
2
+ require "addressable/template"
3
+ # require 'uri'
4
+ require_relative 'test_filters'
5
+ require_relative 'test_builder'
6
+
7
+ require_relative 'data_filters'
8
+ require_relative 'data_builder'
9
+ module NCCConfidence
10
+ class URL
11
+ class << self
12
+ attr_accessor :api_key
13
+ Base = "https://api.siteconfidence.co.uk/current"
14
+ def build test_filters, data_filters
15
+ t_filter = test_filters.class == String ? test_filters : T_Filters.build(test_filters)
16
+ d_filter = data_filters.class == String ? data_filters : D_Filters.build(data_filters)
17
+
18
+ URI.encode("#{Base}/#{self.api_key}/Return/#{d_filter}#{t_filter}")
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module NCCConfidence
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,36 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+ require_relative "nccconfidence/version"
4
+ require_relative "nccconfidence/url_builder"
5
+ require_relative "nccconfidence/http_client"
6
+
7
+
8
+ module NCCConfidence
9
+ class << self
10
+ def api_key= key
11
+ URL.api_key = key
12
+ end
13
+
14
+ def query
15
+ test_filter,data_filter = yield(Builder::Test,Builder::Data)
16
+ request = {
17
+ method: 'GET',
18
+ url: URL.build(test_filter,data_filter)
19
+ }
20
+ make_request(request)
21
+ end
22
+
23
+ private
24
+ def make_request request
25
+ puts request[:url]
26
+ http = Http.request do
27
+ set_uri request[:url]
28
+ end
29
+
30
+ http.make_request_of request[:method]
31
+ JSON.parse(http.body)
32
+ end
33
+
34
+ end
35
+ end
36
+
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: NCCConfidence
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Thermatix
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: addressable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.3.8
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.3.8
27
+ - !ruby/object:Gem::Dependency
28
+ name: curb
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: '0.88'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: '0.88'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.8.3
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.8.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ description:
84
+ email:
85
+ - mbeckerwork@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - NCCConfidence.gemspec
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - lib/nccconfidence.rb
102
+ - lib/nccconfidence/data_builder.rb
103
+ - lib/nccconfidence/data_filters.rb
104
+ - lib/nccconfidence/http_client.rb
105
+ - lib/nccconfidence/url_builder.rb
106
+ - lib/nccconfidence/version.rb
107
+ homepage: https://github.com/Thermatix/NCCConfidence_API
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.4.5
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: This is a gem to make queries to NCC Site confidence API
131
+ test_files: []