hitblocks 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f51bc3e7252432d4752b230387f3ad9a9a088a5b
4
+ data.tar.gz: f0deb368ce017ef5fad18896cd2e884cb3db386d
5
+ SHA512:
6
+ metadata.gz: a774182b3f84b6d21772d1957c49ee233de081320847feb7dcfa4c1661cb48528de7670b7daa1d0d765eb2e0bd3b353e56bdf912a68235c114ca330867555c89
7
+ data.tar.gz: ad34b7c1a18aa498dfa77a37f22a44dd2d9615c57be806ef1922b43ac801c40cbb655baa35c52e09df511e079ee861903fd73346f676f502b28e2c1725ce7462
@@ -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
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ SimpleCov.start do
2
+ add_group "lib", "lib"
3
+ end
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.15.1
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in hitblocks.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'webmock'
8
+ gem 'vcr'
9
+ gem 'byebug'
10
+ gem 'pry'
11
+ gem 'pry-byebug'
12
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Nolan Tait
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,39 @@
1
+ # Hitblocks
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/hitblocks`. 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 'hitblocks'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install hitblocks
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/hitblocks.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -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 "hitblocks"
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,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "hitblocks/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hitblocks"
8
+ spec.version = Hitblocks::VERSION
9
+ spec.authors = ["Hitblocks"]
10
+ spec.email = ["admin@hitblocks.ai"]
11
+
12
+ spec.summary = %q{A API wrapper for Hitblocks.ai API.}
13
+ spec.homepage = "https://docs.hitblocks.ai"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.15"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "simplecov", "~> 0.14.1"
27
+ spec.add_development_dependency "byebug", "~> 9.0"
28
+ spec.add_dependency "httparty", "~> 0.15.0"
29
+ end
@@ -0,0 +1,110 @@
1
+ #Hitblocks Ruby bindings
2
+ # API spec at https://docs.hitblocks.ai
3
+
4
+ require "httparty"
5
+ require "json"
6
+
7
+ require "hitblocks/version"
8
+ require "hitblocks/errors"
9
+ require "hitblocks/hitblock"
10
+ require "hitblocks/list"
11
+ require "hitblocks/item"
12
+ require "hitblocks/error"
13
+ require "hitblocks/hit"
14
+
15
+ module Hitblocks
16
+
17
+ @api_base = 'http://internuncio-prototype-staging.herokuapp.com/api/'
18
+
19
+ class << self
20
+ attr_accessor :api_base, :api_key
21
+
22
+ def api_key
23
+ @api_key ||= raise Hitblocks::APIKeyNotSet, "API key is not set. Use Hitblocks.api_key = 'xxxxxxxxxxxx' to set it."
24
+ end
25
+ end
26
+
27
+ def self.construct_HIT(parsed_response)
28
+ Hitblocks::HIT.new(
29
+ url: parsed_response["url"],
30
+ service: parsed_response["service"],
31
+ status: parsed_response["status"],
32
+ created: parsed_response["created"],
33
+ item: construct_item(parsed_response["item"])
34
+ )
35
+ end
36
+
37
+
38
+ def self.construct_from(response)
39
+ parsed_response = response.parsed_response
40
+ if parsed_response["object"]
41
+ self.send("construct_#{parsed_response["object"]}", parsed_response)
42
+ else
43
+ construct_error(parsed_response)
44
+ end
45
+ end
46
+
47
+ def self.construct_error(parsed_response)
48
+ error = parsed_response["error"]
49
+ if error.nil?
50
+ error = parsed_response["errors"]
51
+ end
52
+ Hitblocks::Error.new(
53
+ error: error,
54
+ status: parsed_response["status"]
55
+ )
56
+ end
57
+
58
+ def self.construct_list(parsed_response)
59
+ data = parsed_response["data"]
60
+ list_items = []
61
+ data.each do |object|
62
+ list_items.push(self.send("construct_#{object["object"]}", object))
63
+ end
64
+ Hitblocks::List.new(
65
+ data: list_items
66
+ )
67
+ end
68
+
69
+ def self.construct_item(item)
70
+ Hitblocks::Item.new(
71
+ id: item["id"],
72
+ type: item["type"],
73
+ created: item["created"],
74
+ cost: item["cost"],
75
+ currency: item["currency"],
76
+ status: item["status"]
77
+ )
78
+ end
79
+
80
+ def self.construct_hitblock(parsed_response)
81
+ Hitblocks::Hitblock.new(
82
+ id: parsed_response["id"],
83
+ title: parsed_response["title"],
84
+ description: parsed_response["description"],
85
+ type: parsed_response["type"],
86
+ created: parsed_response["created"],
87
+ cost_per_item: parsed_response["cost_per_item"],
88
+ workers_per_item: parsed_response["workers_per_item"],
89
+ currency: parsed_response["currency"],
90
+ items: construct_items(parsed_response["items"])
91
+ )
92
+ end
93
+
94
+ def self.construct_items(item_list)
95
+ items = []
96
+
97
+ item_list.each do |item|
98
+ items.push(Hitblocks::Item.new(
99
+ id: item["id"],
100
+ type: item["type"],
101
+ created: item["created"],
102
+ cost: item["cost"],
103
+ currency: item["currency"],
104
+ status: item["status"]
105
+ ))
106
+ end
107
+
108
+ return items
109
+ end
110
+ end
@@ -0,0 +1,17 @@
1
+ module Hitblocks
2
+
3
+ class Error
4
+
5
+ attr_reader :error, :status
6
+
7
+ def initialize(params)
8
+ @error = params[:error]
9
+ @status = params[:status]
10
+
11
+ if @error.match /Invalid Token/
12
+ raise Hitblocks::APIKeyIncorrect, "Your API key is incorrect. Please double check and set the value with Hitblocks.api_key = 'YOUR-API-KEY-HERE'"
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ module Hitblocks
2
+
3
+ class MissingParametersError < StandardError
4
+ end
5
+
6
+ class APIKeyNotSet < StandardError
7
+ end
8
+
9
+ class APIKeyIncorrect < StandardError
10
+ end
11
+
12
+ end
@@ -0,0 +1,15 @@
1
+ module Hitblocks
2
+
3
+ class HIT
4
+
5
+ def initialize(params)
6
+ @url = params["url"],
7
+ @service = params["service"],
8
+ @status = params["status"],
9
+ @created = params["created"],
10
+ @item = params[:item]
11
+ end
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,52 @@
1
+ module Hitblocks
2
+ class Hitblock
3
+ include HTTParty
4
+
5
+ attr_accessor :id
6
+ attr_reader :items
7
+
8
+ class << self
9
+ def retrieve(id = nil)
10
+ self.base_uri Hitblocks.api_base
11
+ raise_missing_parameters if id.nil?
12
+ response = self.get("/hitblocks/#{id}",
13
+ basic_auth: {
14
+ username: Hitblocks.api_key,
15
+ })
16
+
17
+ Hitblocks.construct_from(response)
18
+ end
19
+
20
+ def list
21
+ self.base_uri Hitblocks.api_base
22
+ response = self.get("/hitblocks",
23
+ basic_auth: {
24
+ username: Hitblocks.api_key,
25
+ })
26
+
27
+ Hitblocks.construct_from(response)
28
+ end
29
+ end
30
+
31
+ def initialize(params = {})
32
+ self.class.raise_missing_parameters if params.fetch(:id, nil).nil?
33
+ @id = params[:id]
34
+ @title = params[:title]
35
+ @description = params[:description]
36
+ @type = params[:type]
37
+ @created = params[:created]
38
+ @cost_per_item = params[:cost_per_item]
39
+ @workers_per_item = params[:workers_per_item]
40
+ @currency = params[:currency]
41
+ @items = params[:items]
42
+ end
43
+
44
+
45
+ private
46
+
47
+ def self.raise_missing_parameters
48
+ raise Hitblocks::MissingParametersError, "Missing ID Parameter"
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,77 @@
1
+ module Hitblocks
2
+
3
+ class Item
4
+ include HTTParty
5
+
6
+ attr_accessor :id
7
+
8
+
9
+ def initialize(params = {})
10
+ self.class.raise_missing_parameters if params.fetch(:id, nil).nil?
11
+ @id = params[:id]
12
+ end
13
+
14
+ class << self
15
+ def list
16
+ self.base_uri Hitblocks.api_base
17
+ response = self.get('/items',
18
+ basic_auth: { username: Hitblocks.api_key }
19
+ )
20
+
21
+ Hitblocks.construct_from(response)
22
+ end
23
+
24
+ def retrieve(id = nil)
25
+ self.raise_missing_parameters unless id
26
+ self.base_uri Hitblocks.api_base
27
+ response = self.get("/items/#{id}",
28
+ basic_auth: { username: Hitblocks.api_key }
29
+ )
30
+
31
+ Hitblocks.construct_from(response)
32
+ end
33
+
34
+ def create(params)
35
+ self.base_uri Hitblocks.api_base
36
+ payload = Hash.new
37
+ payload[:item] = params.reject {|x| x == :hitblock}
38
+ response = self.post("/hitblocks/#{params[:hitblock].id}/items",
39
+ body: payload.to_json,
40
+ headers: {
41
+ 'Content-Type' => 'application/json',
42
+ 'Accept' => 'application/json'
43
+ },
44
+ basic_auth: { username: Hitblocks.api_key }
45
+ )
46
+
47
+ Hitblocks.construct_from(response)
48
+ end
49
+ end
50
+
51
+ def delete
52
+ self.class.base_uri Hitblocks.api_base
53
+ response = self.class.delete("/items/#{self.id}",
54
+ basic_auth: { username: Hitblocks.api_key }
55
+ )
56
+
57
+ return response
58
+ end
59
+
60
+ def post
61
+ self.class.base_uri Hitblocks.api_base
62
+ response = self.class.post("/items/#{self.id}/post",
63
+ basic_auth: { username: Hitblocks.api_key }
64
+ )
65
+
66
+ Hitblocks.construct_from(response)
67
+ end
68
+
69
+ private
70
+
71
+ def self.raise_missing_parameters
72
+ raise Hitblocks::MissingParametersError, "Missing ID Parameter"
73
+ end
74
+
75
+ end
76
+
77
+ end
@@ -0,0 +1,10 @@
1
+ module Hitblocks
2
+ class List
3
+ attr_reader :data
4
+
5
+ def initialize(data)
6
+ @data = data[:data]
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Hitblocks
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hitblocks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Hitblocks
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.14.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.14.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '9.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '9.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: httparty
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.15.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.15.0
97
+ description:
98
+ email:
99
+ - admin@hitblocks.ai
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".simplecov"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - hitblocks.gemspec
115
+ - lib/hitblocks.rb
116
+ - lib/hitblocks/error.rb
117
+ - lib/hitblocks/errors.rb
118
+ - lib/hitblocks/hit.rb
119
+ - lib/hitblocks/hitblock.rb
120
+ - lib/hitblocks/item.rb
121
+ - lib/hitblocks/list.rb
122
+ - lib/hitblocks/version.rb
123
+ homepage: https://docs.hitblocks.ai
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.6.12
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: A API wrapper for Hitblocks.ai API.
147
+ test_files: []