Skip to content

Commit

Permalink
create file client
Browse files Browse the repository at this point in the history
  • Loading branch information
neomatrixcode committed Jul 25, 2017
1 parent 6827766 commit 3568ccb
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/client.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
type Client
Query::Function
serverUrl::Function
serverAuth::Function
end

type Result
Info
Data::String
end

function Query(url::String,data::String; vars::Dict=Dict(),auth::String="Bearer 0000")
r=post(url; json = Dict("query"=>data,"variables" => vars),headers = Dict("Accept" => "application/json","Content-Type" => "application/json" ,"Authorization" => auth))
content=""
r.status == 200 ? map(x -> (content*="$(Char(x))"), r.data): content="{\"data\":{}}"
return Result(r,content)
end

function GraphQLClient(url::String,auth::String="Bearer 0000")

my_url::String= url
my_auth::String= auth

function serverUrl(url::String)
my_url = url
end

function serverAuth(auth::String)
my_auth= auth
end

function Query(data::String;vars::Dict=Dict())
r=post(my_url; json = Dict("query"=>data,"variables" => vars),headers = Dict("Accept" => "application/json","Content-Type" => "application/json" ,"Authorization" => my_auth))
content=""
r.status == 200 ? map(x -> (content*="$(Char(x))"), r.data): content="{\"data\":{}}"
return Result(r,content)
end

return Client(Query,serverUrl,serverAuth)
end

0 comments on commit 3568ccb

Please sign in to comment.