spigot 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -0
- data/lib/spigot/map/definition.rb +1 -1
- data/lib/spigot/version.rb +1 -1
- data/spec/spigot/map/definition_spec.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b31cf21b89e530eb6984aecbe4a22e0bbd82f6f3
|
4
|
+
data.tar.gz: bc24b6dc03440a7236c4bdc9e5cdb937a2841341
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a17888d4095a7d086a6ef85bd62f886521f0c1cac607e97ea7937d1bd6902ef479873cb9ab7c25056516dd58795cfdc68f71ab8c55165c380fa5b1d21235237f
|
7
|
+
data.tar.gz: 434d19e5f3b2a847aa1a2e0328cc50a11d20c07673e177332a2fb87005fe8ae5bb53da09a9a543008f5b3df0faae7a321d0766c13e66170a4e4107c25224ee27
|
data/README.md
CHANGED
@@ -35,6 +35,25 @@ Spigot produces a map of the raw API data you receive to columns in your databas
|
|
35
35
|
|
36
36
|
Much better.
|
37
37
|
|
38
|
+
## Usage
|
39
|
+
|
40
|
+
This is an example implementation. Assuming you have a User model in your database and you wish to capture the `id`, `name`, `login`, and `avatar_url` from the API payload.
|
41
|
+
|
42
|
+
require 'open-uri'
|
43
|
+
require 'json'
|
44
|
+
|
45
|
+
Spigot.resource :user do
|
46
|
+
id :github_id
|
47
|
+
name :name
|
48
|
+
login :username
|
49
|
+
avatar_url :image_url
|
50
|
+
end
|
51
|
+
|
52
|
+
data = JSON.parse open('https://api.github.com/users/mwerner').read
|
53
|
+
User.spigot.create(data)
|
54
|
+
# #<User id: 1, name: "Matthew Werner", github_id: 50568, username: "mwerner", avatar_url: "https://avatars.githubusercontent.com/u/50568">
|
55
|
+
|
56
|
+
|
38
57
|
## Installation
|
39
58
|
|
40
59
|
Add this line to your application's Gemfile:
|
data/lib/spigot/version.rb
CHANGED
@@ -77,6 +77,13 @@ describe Spigot::Map::Definition do
|
|
77
77
|
subject.instance_variable_get(:@parse).should_not be_nil
|
78
78
|
subject.instance_variable_get(:@children).length.should eq(0)
|
79
79
|
end
|
80
|
+
|
81
|
+
it 'requires a attribute param to parse block' do
|
82
|
+
subject = Spigot::Map::Definition.define(resource, :foo, 'bar') { |val| "formatted-#{val}" }
|
83
|
+
subject.instance_variable_get(:@parse).should_not be_nil
|
84
|
+
subject.instance_variable_get(:@children).length.should eq(0)
|
85
|
+
subject.parse(foo: 'baz').should eq({bar: 'formatted-baz'})
|
86
|
+
end
|
80
87
|
end
|
81
88
|
|
82
89
|
context '#to_hash' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spigot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Werner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|