This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using RestSharp and Json.Net | |
// client and authentication | |
var client = new RestClient("http://vinexplosion.com/api/"); | |
client.Authenticator = new HttpBasicAuthenticator("username", "password"); | |
// request | |
var request = new RestRequest("vin/decode/{vin}/?fuzzy=true", Method.GET); | |
request.AddUrlSegment("vin", "JA4AP3AU5BZ009787"); | |
request.AddHeader("Accept", "application/json"); // use application/xml for xml response | |
// response | |
var response = client.Execute(request); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using jQuery and jQuery-base64 https://github.com/carlo/jquery-base64 | |
var creds = "Basic " + $.base64.encode("username:password"); | |
$.ajax({ | |
url: "http://vinexplosion.com/api/vin/decode/3GYFNAE36CS509361/?fuzzy=true", | |
dataType: "jsonp", | |
beforeSend: function (req) { | |
req.setRequestHeader("Authorization", creds); | |
req.setRequestHeader("Accept", "application/json"); | |
}, | |
success: function(data, status) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//using Base64Coder and google-gson | |
// initiate the http request to the vin explosion api | |
HttpClient client = new DefaultHttpClient(); | |
String getUrl = "http://vinexplosion.com/api/vin/decode/"; | |
getUrl += vin + "/"; | |
getUrl += "?fuzzy=" + URLEncoder.encode("true"); | |
HttpGet get = new HttpGet(getUrl); | |
// set the appropriate request headers | |
get.addHeader("Authorization", "Basic " + Base64Coder.encodeString("username:password")); | |
get.addHeader("Accept", "application/json"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HttpClient client = new HttpClient(); | |
client.BaseAddress = new Uri("http://vinexplosion.com/api/vin/"); | |
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | |
var byteArray = Encoding.ASCII.GetBytes("username:password"); | |
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); | |
// make the request and capture the response | |
var result = client.GetAsync("decode/JA4AP3AU5BZ009787/?fuzzy=true").Result; | |
// grab the json | |
var json = result.Content.ReadAsStringAsync().Result; | |
var rvef = JObject.Parse(json); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using Asp.net and Json.NET | |
HttpClient client = new HttpClient(); | |
client.BaseAddress = new Uri("http://vinexplosion.com/api/"); | |
// credentials | |
var byteArray = Encoding.ASCII.GetBytes("username:password"); | |
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); | |
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | |
// grab most recent model year | |
var respYears = client.GetAsync("vehicle/years").Result; | |
var json = respYears.Content.ReadAsStringAsync().Result; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$creds = "username:password"; | |
$headers = array("Accept: application/json"); | |
// build the curl request | |
$request = curl_init(); | |
curl_setopt($request, CURLOPT_URL, "http://vinexplosion.com/api/vin/decode/3GYFNAE36CS509361/?fuzzy=true"); | |
curl_setopt($request, CURLOPT_USERPWD, $creds); | |
curl_setopt($request, CURLOPT_HTTPHEADER, $headers); | |
curl_setopt($request, CURLOPT_RETURNTRANSFER, true); | |
// exe the request and gather the code and response |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=my access key"); | |
var azureDir = new AzureDirectory(storageAccount, "MyIndexBlobContainerName"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var indexWriter = new IndexWriter(directory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30), true, | |
new IndexWriter.MaxFieldLength(IndexWriter.DEFAULT_MAX_FIELD_LENGTH)); | |
foreach (var book in Books) | |
{ | |
var document = new Document(); | |
// store the Id but don't need to index it | |
document.Add(new Field("Id", | |
book.BookId.ToString(), | |
Field.Store.YES, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IndexSearcher searcher = new IndexSearcher(directory); | |
// for a multi column search | |
var multiParser = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_30, new[] {"Title", "Author"}, | |
new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// parse the query | |
var query = multiParser.Parse(phrase); | |
// search the index and return the top 10 best records | |
var results = searcher.Search(query, 10); | |
// loop over my top 10 hits and display the results to the console | |
foreach (var hit in results.ScoreDocs) | |
{ | |
// gets the document from the hit index | |
var doc = searcher.Doc(hit.Doc); | |
// write out the best books matching my phrase |
OlderNewer