caselaw 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,32 @@
1
+ module Caselaw
2
+ module Cases
3
+ API_ENDPOINT = "cases/"
4
+
5
+ def case(id, full_case = false)
6
+ id_path = id.to_s
7
+ path = API_ENDPOINT + id_path
8
+ path = path + "?full_case=true" if full_case == true
9
+ Hashie::Mash.new(request(path))
10
+ end
11
+
12
+ def cases_by_jurisdiction(jurisdiction_term, num_cases, full_case = false)
13
+ slug = slug(jurisdiction_term)
14
+ path = API_ENDPOINT + "?jurisdiction=" + slug
15
+ path = path + "&full_case=true" if full_case == true
16
+ tempArray = paginated_request(path, num_cases)
17
+ Hashie::Mash.new(resultsCount: tempArray.count, results: tempArray)
18
+ end
19
+
20
+ # Search through text of cases and return cases that contain the word
21
+ def search_cases(term, num_cases, jurisdiction_term=nil)
22
+ if jurisdiction_term != nil
23
+ slug = slug(jurisdiction_term)
24
+ path = API_ENDPOINT + "?search=" + term + "&jurisdiction=" + slug
25
+ else
26
+ path = API_ENDPOINT + "?search=" + term
27
+ end
28
+ tempArray = paginated_request(path, num_cases)
29
+ Hashie::Mash.new(resultsCount: tempArray.count, results: tempArray)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,4 @@
1
+ module Caselaw
2
+ module Citations
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Caselaw
2
+ module Courts
3
+ end
4
+ end
@@ -0,0 +1,17 @@
1
+ module Caselaw
2
+ module Jurisdictions
3
+ API_ENDPOINT = "jurisdictions/"
4
+
5
+ # Return all Jurisdictions
6
+ def search_jurisdictions
7
+ Hashie::Mash.new(request(API_ENDPOINT))
8
+ end
9
+
10
+ # Search for a specific Jurisdiction
11
+ def jurisdiction(jurisdiction_term)
12
+ slug = slug(jurisdiction_term)
13
+ path = API_ENDPOINT + slug
14
+ Hashie::Mash.new(request(path))
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ module Caselaw
2
+ module Reporters
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Caselaw
2
+ module Volumes
3
+ end
4
+ end
@@ -0,0 +1,7 @@
1
+ module Caselaw
2
+ class Error < StandardError; end
3
+ class ConfigurationError < Error; end
4
+ class Forbidden < Error; end
5
+ class Unauthorized < Error; end
6
+ class NotFound < Error; end
7
+ end
@@ -0,0 +1,90 @@
1
+ module Caselaw
2
+ class Jurisdiction
3
+ attr_accessor :name, :id, :slug
4
+
5
+ def initialize(name, id, slug)
6
+ self.name = name
7
+ self.id = id
8
+ self.slug = slug
9
+ end
10
+
11
+ def self.all
12
+ [
13
+ Jurisdiction.new("Alabama", 23, "ala"),
14
+ Jurisdiction.new("Alaska", 53, "alaska"),
15
+ Jurisdiction.new("American Samoa", 58, "am-samoa"),
16
+ Jurisdiction.new("Arizona", 21, "ariz"),
17
+ Jurisdiction.new("Arkansas", 34, "ark"),
18
+ Jurisdiction.new("California", 30, "cal"),
19
+ Jurisdiction.new("Colorado", 31, "colo"),
20
+ Jurisdiction.new("Connecticut", 2, "conn"),
21
+ Jurisdiction.new("Dakota Territory", 55, "dakota-territory"),
22
+ Jurisdiction.new("District of Columbia", 56, "dc"),
23
+ Jurisdiction.new("Delaware", 8, "del"),
24
+ Jurisdiction.new("Florida", 28, "fla"),
25
+ Jurisdiction.new("Georgia", 3, "ga"),
26
+ Jurisdiction.new("Guam", 60, "guam"),
27
+ Jurisdiction.new("Hawaii", 40, "haw"),
28
+ Jurisdiction.new("Idaho", 27, "idaho"),
29
+ Jurisdiction.new("Illinois", 29, "ill"),
30
+ Jurisdiction.new("Indiana", 14, "ind"),
31
+ Jurisdiction.new("Iowa", 45, "iowa"),
32
+ Jurisdiction.new("Kansas", 43, "kan"),
33
+ Jurisdiction.new("Kentucky", 26, "ky"),
34
+ Jurisdiction.new("Louisiana", 10, "la"),
35
+ Jurisdiction.new("Massachusetts", 4, "mass"),
36
+ Jurisdiction.new("Maryland", 50, "md"),
37
+ Jurisdiction.new("Maine", 42, "me"),
38
+ Jurisdiction.new("Michigan", 49, "mich"),
39
+ Jurisdiction.new("Minnesota", 36, "minn"),
40
+ Jurisdiction.new("Mississippi", 16, "miss"),
41
+ Jurisdiction.new("Missouri", 37, "mo"),
42
+ Jurisdiction.new("Montana", 20, "mont"),
43
+ Jurisdiction.new("Native American", 61, "native-american"),
44
+ Jurisdiction.new("Navajo Nation", 41, "navajo-nation"),
45
+ Jurisdiction.new("North Carolina", 5, "nc"),
46
+ Jurisdiction.new("North Dakota", 18, "nd"),
47
+ Jurisdiction.new("Nebraska", 51, "neb"),
48
+ Jurisdiction.new("Nevada", 48, "nev"),
49
+ Jurisdiction.new("New Hampshire", 47, "nh"),
50
+ Jurisdiction.new("New Jersey", 24, "nj"),
51
+ Jurisdiction.new("New Mexico", 52, "nm"),
52
+ Jurisdiction.new("Northern Mariana Islands", 57, "n-mar-i"),
53
+ Jurisdiction.new("New York", 1, "ny"),
54
+ Jurisdiction.new("Ohio", 22, "ohio"),
55
+ Jurisdiction.new("Oklahoma", 13, "okla"),
56
+ Jurisdiction.new("Oregon", 19, "or"),
57
+ Jurisdiction.new("Pennsylvania", 6, "pa"),
58
+ Jurisdiction.new("Puerto Rico", 25, "pr"),
59
+ Jurisdiction.new("Regional", 9, "regional"),
60
+ Jurisdiction.new("Rhode Island", 15, "ri"),
61
+ Jurisdiction.new("South Carolina", 59, "sc"),
62
+ Jurisdiction.new("South Dakota", 54, "sd"),
63
+ Jurisdiction.new("Tennessee", 11, "tenn"),
64
+ Jurisdiction.new("Texas", 32, "tex"),
65
+ Jurisdiction.new("Tribal Jurisdictions", 62, "tribal"),
66
+ Jurisdiction.new("United States", 39, "us"),
67
+ Jurisdiction.new("Utah", 12, "utah"),
68
+ Jurisdiction.new("Virginia", 7, "va"),
69
+ Jurisdiction.new("Virgin Islands", 44, "vi"),
70
+ Jurisdiction.new("Vermont", 17, "vt"),
71
+ Jurisdiction.new("Washington", 38, "wash"),
72
+ Jurisdiction.new("Wisconsin", 46, "wis"),
73
+ Jurisdiction.new("West Virginia", 35, "w-va"),
74
+ Jurisdiction.new("Wyoming", 33, "wyo")
75
+ ]
76
+ end
77
+
78
+ def self.get_by_name(name)
79
+ jurisdiction = all.find { |j| j.name.downcase == name.downcase }
80
+ fail(Caselaw::NotFound, "Jurisdiciton not found, please check spelling.") if jurisdiction.nil?
81
+ jurisdiction.slug
82
+ end
83
+
84
+ def self.get_by_id(id)
85
+ jurisdiction = all.find { |j| j.id == id }
86
+ fail(Caselaw::NotFound, "Jurisdiciton not found, please check id referenced.") if jurisdiction.nil?
87
+ jurisdiction.slug
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,61 @@
1
+ require "httparty"
2
+ require "hashie"
3
+
4
+ module Caselaw
5
+ module Request
6
+ API_ROOT = "https://api.case.law/v1/"
7
+
8
+ def request(path)
9
+ token = api_key || Caselaw.configuration[:api_key]
10
+ fail(Caselaw::ConfigurationError, "API key is required.") if token.nil?
11
+
12
+ res = HTTParty.get(API_ROOT + path, headers: {"Authorization" => "Token " + token})
13
+ case res.code
14
+ when 200
15
+ parsed_response(res)
16
+ when 404
17
+ fail(Caselaw::NotFound)
18
+ end
19
+ end
20
+
21
+ def paginated_request(path, num)
22
+ token = api_key || Caselaw.configuration[:api_key]
23
+ fail(Caselaw::ConfigurationError, "API key is required.") if token.nil?
24
+
25
+ count = 0
26
+ pageCount = 1
27
+ nextPageExists = true
28
+ tempArray = []
29
+ path = API_ROOT + path
30
+
31
+ initialRes = HTTParty.get(path, headers: {"Authorization" => "Token " + token})
32
+ initialRes = initialRes.parsed_response
33
+
34
+ while nextPageExists && count <= num
35
+ puts "-- | Page " + pageCount.to_s
36
+ res = HTTParty.get(path, headers: {"Authorization" => "Token " + token})
37
+ res = res.parsed_response
38
+ data = res['results']
39
+
40
+ count += data.count
41
+ pageCount += 1
42
+ tempArray.push(*data)
43
+ res['next'] != nil ? path = res['next'] : nextPageExists = false
44
+ end
45
+ tempArray = tempArray[0, num] if tempArray.count > num
46
+ tempArray
47
+ end
48
+
49
+ def parsed_response(res)
50
+ res.parsed_response
51
+ end
52
+
53
+ def slug(jurisdiction_term)
54
+ if jurisdiction_term.is_a?(String)
55
+ Caselaw::Jurisdiction.get_by_name(jurisdiction_term)
56
+ elsif jurisdiction_term.is_a?(Integer)
57
+ Caselaw::Jurisdiction.get_by_id(jurisdiction_term)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ module Caselaw
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,13 @@
1
+ require 'caselaw'
2
+
3
+ RSpec.describe Caselaw do
4
+ it "has a version number" do
5
+ expect(Caselaw::VERSION).not_to be nil
6
+ end
7
+
8
+ describe ".new" do
9
+ it "returns a new client instance" do
10
+ expect(Caselaw.new).to be_a(Caselaw::Client)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,69 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Caselaw::Client do
4
+ let(:client) { Caselaw::Client.new(api_key: "SECRET_KEY") }
5
+ before(:each) { Caselaw.reset_configuration }
6
+
7
+ describe "new" do
8
+ it "requires a hash argument" do
9
+ expect { Caselaw::Client.new("Tom") }
10
+ .to raise_error(ArgumentError, "API key hash is required.")
11
+ end
12
+ end
13
+
14
+ describe "slug" do
15
+ it "gets 62 jurisdictions" do
16
+ expect(Caselaw::Jurisdiction.all.length).to eq 62
17
+ end
18
+
19
+ it "finds a slug by name, case-insensitive" do
20
+ expect(Caselaw::Jurisdiction.get_by_name("Colorado")).to eq "colo"
21
+ expect(Caselaw::Jurisdiction.get_by_name("colorado")).to eq "colo"
22
+ end
23
+
24
+ it "finds a slug by id" do
25
+ expect(Caselaw::Jurisdiction.get_by_id(31)).to eq "colo"
26
+ end
27
+
28
+ context "when jurisdiction does not exist" do
29
+ it "raises Caselaw::NotFound" do
30
+ expect { Caselaw::Jurisdiction.get_by_name("Tom") }.to raise_error(Caselaw::NotFound)
31
+ expect { Caselaw::Jurisdiction.get_by_id(2000) }.to raise_error(Caselaw::NotFound)
32
+ end
33
+ end
34
+ end
35
+
36
+ describe "get jurisdictions" do
37
+ before { stub("jurisdictions/", "jurisdictions.json") }
38
+
39
+ it "returns all jurisdictions" do
40
+ search = client.search_jurisdictions
41
+ results = client.search_jurisdictions['results']
42
+ expect(search).to be_a Hashie::Mash
43
+ expect(results).to be_an(Array)
44
+ end
45
+ end
46
+
47
+ describe "case" do
48
+ before { stub("cases/1021505", "case.json") }
49
+
50
+ it "returns case instance" do
51
+ case_instance = client.case(1021505)
52
+ expect(case_instance).to be_a Hashie::Mash
53
+ expect(case_instance.id).to eq 1021505
54
+ end
55
+
56
+ context "when case does not exist" do
57
+ before {stub_request(:get, "https://api.case.law/v1/cases/1021505000")
58
+ .with(
59
+ headers: {
60
+ 'Authorization'=>'Token SECRET_KEY'
61
+ })
62
+ .to_return(status: 200, body: "", headers: {})}
63
+
64
+ it "raises Caselaw::NotFound" do
65
+ expect(client.case(1021505000).to raise_error(Caselaw::NotFound))
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,39 @@
1
+ {
2
+ "id": 1021505,
3
+ "url": "https://api.case.law/v1/cases/1021505/",
4
+ "name": "William Stone against William Boreman",
5
+ "name_abbreviation": "Stone v. Boreman",
6
+ "decision_date": "1658",
7
+ "docket_number": "",
8
+ "first_page": "1",
9
+ "last_page": "5",
10
+ "citations": [
11
+ {
12
+ "type": "official",
13
+ "cite": "1 Md. 1"
14
+ }
15
+ ],
16
+ "volume": {
17
+ "url": "https://api.case.law/v1/volumes/32044057896128/",
18
+ "volume_number": "1"
19
+ },
20
+ "reporter": {
21
+ "url": "https://api.case.law/v1/reporters/732/",
22
+ "full_name": "Maryland reports, being a series of the most important law cases argued and determined in the Provincial Court and Court of Appeals of the then province of Maryland, from the year 1700 [i.e. 1658] down to the [end of 1799]"
23
+ },
24
+ "court": {
25
+ "url": "https://api.case.law/v1/courts/md/",
26
+ "id": 8823,
27
+ "slug": "md",
28
+ "name": "Court of Appeals of Maryland",
29
+ "name_abbreviation": "Md."
30
+ },
31
+ "jurisdiction": {
32
+ "url": "https://api.case.law/v1/jurisdictions/md/",
33
+ "id": 50,
34
+ "slug": "md",
35
+ "name": "Md.",
36
+ "name_long": "Maryland",
37
+ "whitelisted": false
38
+ }
39
+ }
@@ -0,0 +1,63 @@
1
+ {
2
+ "id": 1021505,
3
+ "url": "https://api.case.law/v1/cases/1021505/",
4
+ "name": "William Stone against William Boreman",
5
+ "name_abbreviation": "Stone v. Boreman",
6
+ "decision_date": "1658",
7
+ "docket_number": "",
8
+ "first_page": "1",
9
+ "last_page": "5",
10
+ "citations": [
11
+ {
12
+ "type": "official",
13
+ "cite": "1 Md. 1"
14
+ }
15
+ ],
16
+ "volume": {
17
+ "url": "https://api.case.law/v1/volumes/32044057896128/",
18
+ "volume_number": "1"
19
+ },
20
+ "reporter": {
21
+ "url": "https://api.case.law/v1/reporters/732/",
22
+ "full_name": "Maryland reports, being a series of the most important law cases argued and determined in the Provincial Court and Court of Appeals of the then province of Maryland, from the year 1700 [i.e. 1658] down to the [end of 1799]"
23
+ },
24
+ "court": {
25
+ "url": "https://api.case.law/v1/courts/md/",
26
+ "id": 8823,
27
+ "slug": "md",
28
+ "name": "Court of Appeals of Maryland",
29
+ "name_abbreviation": "Md."
30
+ },
31
+ "jurisdiction": {
32
+ "url": "https://api.case.law/v1/jurisdictions/md/",
33
+ "id": 50,
34
+ "slug": "md",
35
+ "name": "Md.",
36
+ "name_long": "Maryland",
37
+ "whitelisted": false
38
+ },
39
+ "casebody": {
40
+ "status": "ok",
41
+ "data": {
42
+ "head_matter": "PROVINCIAL COURT,\nWilliam Stone against William Boreman.\n1658.\non Tuesday, August 2, 1659.\nPresent — His Excellency, Josias Fendall, Esq. Governor and Chief Justice.\n(\"Philip Calvert, Esq. Secretary,!\nThe Hon. -I Col. Nathaniel Utye, Esq. > Councillors.\n[Mr. Edward Lloyd, Esq. J\nUPON the difference between Capt. William Stone and William Boreman, touching the said Boreman!s land at Nanjemoy, it appearing to this Court that the said Bore-man did not legally pursue his warrant for four hundred acres of land within the time of the said warrant prescribed — It is ordered by this Court that a patent immediately be passed to Capt. William Stone of the land by him demanded, and in regard that the said Boremarfs right to so much land doth yet remain unto him ; and the surveyor did, in his own wrong, survey and receive pay for survey of that land at Nanjemoy. It is ordered also by the Court that the said Boreman shall have 400 acres in some other convenient place, and the surveyor to lay it out without satisfaction or pay from the said Boreman.\nPROVINCIAL COURT, FEBRUARY, 1660.\n“ WHEREAS Edward Lloyd, maketh it appear to this “ Court per draughts and the plots of land surveyed for him “ in Wye River, that his long lines running S. E. he also “ having purchased two patents, next adjoining upon him ; “ thelong lines of which patents, running E. per which occa- “ sion he wants much of his due proportion of land. Upon u his motion and the consideration thereof, the Court hath “ thought fit and ordered that the long lines of the land “ purchased of William Granger shall run S. E. provided “ it prejudice no survey made before these presents.”\nLiber S.\nAt a Court holden in Anne Arundel County,",
43
+ "parties": [
44
+ "William Stone against William Boreman."
45
+ ],
46
+ "judges": [
47
+ "Present — His Excellency, Josias Fendall, Esq. Governor and Chief Justice."
48
+ ],
49
+ "attorneys": [
50
+ "(\"Philip Calvert, Esq. Secretary,!",
51
+ "The Hon. -I Col. Nathaniel Utye, Esq. > Councillors.",
52
+ "[Mr. Edward Lloyd, Esq. J"
53
+ ],
54
+ "opinions": [
55
+ {
56
+ "text": "WAS called before the Board George Dorr el, James Homewood, and other the inhabitants of the County of Anne Arundel, (being warned to appear upon special writ) who have not subscribed the engagement nor made oath of fidelity to his Lordship, according to the act of Assembly in that case provided, to shew cause why the several lands or plantations seated and planted by them should not be seized into the Lord Proprietary’s hands, they having not performed the conditions of plantations propounded and granted by his Lordship, whereby they may be made capable and assured of enjoying the same.\nIn answer thereto, George Dorr ell saith that he hath not subscribed the engagement, neither will he make oath of fidelity to his Lordship ; and further, that part of the land he now enjoyeth was taken up by him upon his own right for his transport, and part he purchased, and bought of Richard Youngs deceased, before the engagement was propounded, or tendered according to the act.\nJames Hometvood and Thomas Homewood say the same touching the engagement and oath of fidelity. Yet they presume to have right to the land they enjoy, for that they made oath of fidelity in Capt. Stone’s time of government, and seated their lands upon his Lordship’s promise.\nCol. Nathaniel Utye being desired by the Governor, to deliver his opinion in this point, saith, that those people who deny to comply with and fulfil such conditions of plantation propounded by his Lordship ought not to enjoy their lands although seated by them.\nMr. Edward Lloyd saith, that the articles not being performed, the land to belong to the Proprietary ; yet in his judgment there ought to be some consideration for the pains of clearing and charges of building upon the same.\nMr. Secretary. That no one can claim any land in this province but conditionally : that those conditions are not performed by those who have not subscribed the engagement, and therefore, that the lands of the non-subscribers be seized into the hands of the Lord Proprietary.\nGovernor. Whereas the Lord Proprietary did grant land to those who transported themselves into the Province provided that they fulfilled such conditions as his Lordship had thereunto annexed, which those people who did not take the oath of fidelity, or in room thereof, who did not subscribe the engagement, and do still refuse so to do, have no right or title to the land by them taken up ; and that the lands be therefore seized into the hands of the Lord Proprietary.\nIt is therefore ordered that the land of the said George Dorrell, and the lands also of all the other several inhabitants of the County of Anne Arundel, refusing to take the oath of fidelity to his Lordship, or subscribe the engagement according to the conditions of plantation by his said Lordship propounded, and instructions thereunto annexed, be forthwith seized into the hands of the Lord Proprietary.\nVide Lib. S. one of the Court of Appeals Records.\nProclamation, by the Lieutenant and Governor of Maryland.\nWhereas upon the surrender of the government to me by his Lordship’s Lieutenant on the 24th of March last past, amongst other things, it was then agreed that the oath of fidelity should not be pressed upon the inhabitants then residing within this province. But that in place and stead thereof an engagement should be taken in manner and form, as in those articles, relation unto them being had, more at large appeareth. And whereas by an act of this last General Assembly the said articles are confirmed, and the said engagement by law commanded to be taken. To the end the said articles may be inviolably observed, and that all jealousies and fears be removed — -These are in the Lord Proprietary’s name, strictly to charge, and command all persons whatsoever to make their repair to their clerks of their respective County Courts, at or before the 20th day of August, next ensuing, to make their subscriptions to the said engagement, or else that they provide themselves to depart the Province by the 25th day of March next; And to declare that all person's who shall be found in any part of this Province after the 25th of March afore said, shall be proceeded against as rebels and traitors.\nGiven under my hand this 23d of July, 1658.\nJosias Fendall.\nSee Liber S. fol. 71. the oldest record book of the prti ceedings in the Court of Appeals.\nWRIT.\nThese are to will and require you in the Lord Proprietary’s name, to summon all persons who have not subscribed the engagement within your County to appear at the meeting-house in the said County upon Tuesday, the 2d day of August next, then and there to shew cause why the lands in their possession, or pretended to be held by title derived from them, shall not be seized into the hands of the Lord Proprietary. Hereof fail not as you will answer the contrary at your peril.\nGiven under my hand this 23d day of July, 1659.\nJosias Fendall.\nTo the Sheriifof, &c.\nSee Liber S. fol. 279. Record of the Court of Appeals.",
57
+ "type": "majority",
58
+ "author": null
59
+ }
60
+ ]
61
+ }
62
+ }
63
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "url": "https://api.case.law/v1/jurisdictions/colo/",
3
+ "id": 31,
4
+ "slug": "colo",
5
+ "name": "Colo.",
6
+ "name_long": "Colorado",
7
+ "whitelisted": false
8
+ }