cloth 0.0.1

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: b9692d7a1b35d348a10c02be04bcb6eba99d6e35
4
+ data.tar.gz: 6b71f68a0b7ed1674c4e9e4420aec79e2b9ecbe9
5
+ SHA512:
6
+ metadata.gz: 3b13455acf666a243d1d2bc32263972d3762efaeb23a4e4df7f93783457af3a1e901ae9c6d26036c3e71a7ea800fae785518feaffa9b7a31aeea730644e39995
7
+ data.tar.gz: 6f99d65a5ddf3426550c5c288d7875ed2ac1ba915ff75e31698733af55c0c3785504086bc532aff017840872d14107680c467d646c96eae73b57554663bc6e3f
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cloth"
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__)
data/bin/setup ADDED
@@ -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,40 @@
1
+ module Cloth
2
+ class Client
3
+ attr_reader :api_key
4
+ def initialize(api_key = nil)
5
+ @api_key = api_key || Cloth.api_key
6
+ raise Exception, "An API key must be set before the Cloth client can be used. Set an API key with 'Cloth.api_key = ...'" unless @api_key
7
+ end
8
+
9
+ def get(url, options)
10
+ request(:get, url, options)
11
+ end
12
+
13
+ def post(url, options)
14
+ request(:post, url, options)
15
+ end
16
+
17
+ def request(method = :get, url, options)
18
+ fixed_url = url[0] == "/" ? url[1..-1] : url
19
+ Typhoeus::Request.new(
20
+ [Cloth.api_url, fixed_url].join('/'),
21
+ method: method,
22
+ body: options[:body],
23
+ params: options[:params],
24
+ headers: {
25
+ 'Cloth-Api-Key': @api_key
26
+ }.merge(options[:headers])
27
+ ).run
28
+ end
29
+
30
+ class << self
31
+ def get(url, options)
32
+ Cloth.client.get(url, options)
33
+ end
34
+
35
+ def post(url, options)
36
+ Cloth.client.post(url, options)
37
+ end
38
+ end
39
+ end
40
+ end
data/lib/cloth/item.rb ADDED
@@ -0,0 +1,32 @@
1
+ module Cloth
2
+ class Item
3
+ attr_reader :data
4
+ attr_reader :id
5
+
6
+ def recommend
7
+ Cloth.client.post("/api/items/recommend", { id: id, data: data })
8
+ end
9
+
10
+ def unrecommend
11
+ Cloth.client.post("/api/items/unrecommend", { id: id, data: data })
12
+ end
13
+
14
+ def recommendations
15
+ Cloth.client.get("/api/items/#{id}/recommendations")
16
+ end
17
+
18
+ class << self
19
+ def recommend_item(id, data)
20
+ Item.new(id, data).recommend
21
+ end
22
+
23
+ def unrecommend_item(id, data)
24
+ Item.new(id, data).unrecommend
25
+ end
26
+
27
+ def recommendations(id, data)
28
+ Item.new(id, data).recommendations
29
+ end
30
+ end
31
+ end
32
+ end
data/lib/cloth/user.rb ADDED
@@ -0,0 +1,4 @@
1
+ module Cloth
2
+ class User
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module Cloth
2
+ VERSION = "0.0.1".freeze
3
+ end
data/lib/cloth.rb ADDED
@@ -0,0 +1,19 @@
1
+ require "cloth/client"
2
+ require "cloth/item"
3
+ require "cloth/user"
4
+ require "cloth/version"
5
+
6
+ module Cloth
7
+ class << self
8
+ attr_accessor :api_key, :client
9
+ attr_reader :api_url
10
+
11
+ def client
12
+ @_client ||= Cloth::Client.new
13
+ end
14
+
15
+ def api_url
16
+ @api_url ||= "https://api.cloth.network"
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cloth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kristian Freeman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-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.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
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: typhoeus
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.3.0
69
+ description: Give your users what they want. https://cloth.network
70
+ email:
71
+ - kristian@bytesized.xyz
72
+ executables:
73
+ - console
74
+ - setup
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - bin/console
79
+ - bin/setup
80
+ - lib/cloth.rb
81
+ - lib/cloth/client.rb
82
+ - lib/cloth/item.rb
83
+ - lib/cloth/user.rb
84
+ - lib/cloth/version.rb
85
+ homepage: https://cloth.network
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.4.5.1
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: The Ruby bindings for the Cloth API.
109
+ test_files: []