subjoin 0.2.1

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,9 @@
1
+ {
2
+ "self": "http://example.com/posts",
3
+ "related": {
4
+ "href": "http://example.com/articles/1/comments",
5
+ "meta": {
6
+ "count": 10
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "meta": {
3
+ "copyright": "Copyright 2015 Example Corp.",
4
+ "authors": [
5
+ "Yehuda Katz",
6
+ "Steve Klabnik",
7
+ "Dan Gebhardt",
8
+ "Tyler Kellen"
9
+ ]
10
+ },
11
+ "data": {}
12
+ }
13
+
@@ -0,0 +1,12 @@
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
3
+
4
+ require "subjoin"
5
+
6
+ cwd = File.dirname(__FILE__)
7
+
8
+ ERR404 = IO.read(File.join(cwd, "responses", "404.json"))
9
+ ARTICLE = IO.read(File.join(cwd, "responses", "article_example.json"))
10
+ COMPOUND = IO.read(File.join(cwd, "responses", "compound_example.json"))
11
+ LINKS = IO.read(File.join(cwd, "responses", "links.json"))
12
+ META = IO.read(File.join(cwd, "responses", "meta.json"))
@@ -0,0 +1,99 @@
1
+ require "spec_helper"
2
+
3
+ describe Subjoin do
4
+ describe "#get" do
5
+ it "should return parsed JSON" do
6
+ allow_any_instance_of(Faraday::Connection).
7
+ to receive(:get).and_return(double(Faraday::Response, :body => ARTICLE))
8
+ expect(Subjoin::get(URI("http://example.com/articles"))).
9
+ to be_an_instance_of(Hash)
10
+ end
11
+
12
+ it "should send the correct accept header" do
13
+ allow_any_instance_of(Faraday::Connection).
14
+ to receive(:get).
15
+ with(
16
+ URI,
17
+ Hash,
18
+ hash_including("Accept" => "application/vnd.api+json")
19
+ ).and_return(double(Faraday::Response, :body => ARTICLE))
20
+ Subjoin::get(URI("http://example.com/articles"))
21
+ end
22
+
23
+ context "with a hash of parameters" do
24
+ context "including include" do
25
+ before :each do
26
+ expect_any_instance_of(Faraday::Connection).
27
+ to receive(:get).
28
+ with(URI, hash_including("include" => "author,comments"), Hash).
29
+ and_return(double(Faraday::Response, :body => ARTICLE))
30
+ end
31
+
32
+ context "and String for an include parameter" do
33
+ it "should get the URI with the parameter" do
34
+ Subjoin::get(URI("http://example.com/articles"),
35
+ {"include" => "author,comments"})
36
+ end
37
+ end
38
+
39
+ context "and an array of Strings for an include parameter" do
40
+ it "should join the array into a string" do
41
+ Subjoin::get(URI("http://example.com/articles"),
42
+ {"include" => ["author", "comments"]})
43
+ end
44
+ end
45
+ end
46
+
47
+ context "including fields" do
48
+ before :each do
49
+ expect_any_instance_of(Faraday::Connection).
50
+ to receive(:get).
51
+ with(URI, hash_including("fields[article]" => "title,pagecount"), Hash).
52
+ and_return(double(Faraday::Response, :body => ARTICLE))
53
+ end
54
+
55
+ context "as Hash elements for each type" do
56
+ context "where the values are Strings" do
57
+ it "should pass them unchanged" do
58
+ Subjoin::get(URI("http://example.com/articles"),
59
+ {
60
+ "include" => ["author", "comments"],
61
+ "fields[article]" => "title,pagecount"
62
+ })
63
+ end
64
+ end
65
+
66
+ context "where the values are Arrays" do
67
+ it "should join them into a string" do
68
+ Subjoin::get(URI("http://example.com/articles"),
69
+ {
70
+ "include" => ["author", "comments"],
71
+ "fields[article]" => ["title", "pagecount"]
72
+ })
73
+ end
74
+ end
75
+ end
76
+
77
+ context "as a Hash for the whole" do
78
+ it "should turn the keys and values into strings" do
79
+ Subjoin::get(URI("http://example.com/articles"),
80
+ {
81
+ "include" => ["author", "comments"],
82
+ "fields" => {"article" => "title,pagecount"}
83
+ })
84
+ end
85
+
86
+ context "with the individual fields as Arrays of Strings" do
87
+ it "should join those values into Strings" do
88
+ Subjoin::get(URI("http://example.com/articles"),
89
+ {
90
+ "include" => ["author", "comments"],
91
+ "fields" => {"article" => ["title", "pagecount"]}
92
+ })
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
data/subjoin.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'subjoin/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "subjoin"
8
+ spec.version = Subjoin::VERSION
9
+ spec.authors = ["Sean Redmond"]
10
+ spec.email = ["sean.redmond@gmail.com"]
11
+ spec.summary = %q{A practical wrapper for JSON-API interactions.}
12
+ spec.description = %q{A practical wrapper for JSON-API interactions.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "faraday"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "yard"
27
+ end
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: subjoin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Sean Redmond
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: A practical wrapper for JSON-API interactions.
84
+ email:
85
+ - sean.redmond@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - ".yardops"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - lib/subjoin.rb
98
+ - lib/subjoin/attributable.rb
99
+ - lib/subjoin/document.rb
100
+ - lib/subjoin/errors.rb
101
+ - lib/subjoin/identifier.rb
102
+ - lib/subjoin/inclusions.rb
103
+ - lib/subjoin/inheritable.rb
104
+ - lib/subjoin/jsonapi.rb
105
+ - lib/subjoin/link.rb
106
+ - lib/subjoin/linkable.rb
107
+ - lib/subjoin/meta.rb
108
+ - lib/subjoin/metable.rb
109
+ - lib/subjoin/relationship.rb
110
+ - lib/subjoin/resource.rb
111
+ - lib/subjoin/version.rb
112
+ - spec/document_spec.rb
113
+ - spec/identifier_spec.rb
114
+ - spec/inclusions_spec.rb
115
+ - spec/inheritable_resource_spec.rb
116
+ - spec/link_spec.rb
117
+ - spec/meta_spec.rb
118
+ - spec/relationship_spec.rb
119
+ - spec/resource_spec.rb
120
+ - spec/responses/404.json
121
+ - spec/responses/article_example.json
122
+ - spec/responses/compound_example.json
123
+ - spec/responses/links.json
124
+ - spec/responses/meta.json
125
+ - spec/spec_helper.rb
126
+ - spec/subjoin_spec.rb
127
+ - subjoin.gemspec
128
+ homepage: ''
129
+ licenses:
130
+ - MIT
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 2.4.5
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: A practical wrapper for JSON-API interactions.
152
+ test_files:
153
+ - spec/document_spec.rb
154
+ - spec/identifier_spec.rb
155
+ - spec/inclusions_spec.rb
156
+ - spec/inheritable_resource_spec.rb
157
+ - spec/link_spec.rb
158
+ - spec/meta_spec.rb
159
+ - spec/relationship_spec.rb
160
+ - spec/resource_spec.rb
161
+ - spec/responses/404.json
162
+ - spec/responses/article_example.json
163
+ - spec/responses/compound_example.json
164
+ - spec/responses/links.json
165
+ - spec/responses/meta.json
166
+ - spec/spec_helper.rb
167
+ - spec/subjoin_spec.rb
168
+ has_rdoc: