Skip to content

Commit

Permalink
Get endpoints cleanup
Browse files Browse the repository at this point in the history
Use metaprogramming to generate GET endpoints having no required
arguments
  • Loading branch information
randyzwitch committed Dec 1, 2017
1 parent 1ed9c55 commit 3600d4f
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 305 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: julia
os:
- linux
- osx
julia:
- 0.6
- nightly
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The Twitter.jl package is licensed under the MIT "Expat" License:

> Copyright (c) 2014: Randy Zwitch.
> Copyright (c) 2017: Randy Zwitch.
>
> Permission is hereby granted, free of charge, to any person obtaining
> a copy of this software and associated documentation files (the
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Twitter

OSX/Linux: [![Build Status](https://travis-ci.org/randyzwitch/Twitter.jl.png)](https://travis-ci.org/randyzwitch/Twitter.jl)
Linux: [![Build Status](https://travis-ci.org/randyzwitch/Twitter.jl.png)](https://travis-ci.org/randyzwitch/Twitter.jl)
<br>
Windows: [![Build status](https://ci.appveyor.com/api/projects/status/09qykgs7l2fakcvh?svg=true)](https://ci.appveyor.com/project/randyzwitch/twitter-jl)

Expand Down
8 changes: 1 addition & 7 deletions src/Twitter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ export get_direct_messages,
post_lists_members_destroyall,
get_lists_ownerships,
get_saved_searches_list,
#get_saved_searches_show_id,
#post_saved_searches_create,
#post_saved_searches_destroy_id,
get_search_tweets,
post_users_report_spam,
post_streaming_filtered,
Expand Down Expand Up @@ -102,7 +99,6 @@ export get_direct_messages,
post_update_delivery_device,
post_update_profile,
post_update_profile_background,
# post_update_profile_colors,
post_update_profile_image,
get_blocks_list,
get_blocks_ids,
Expand Down Expand Up @@ -135,16 +131,14 @@ include("favorites.jl")
include("friendsfollowers.jl")
include("general.jl")
include("geo.jl")
include("get_no_required_args.jl")
include("no_required_args.jl")
include("lists.jl")
include("oauth.jl")
include("parse.jl")
#include("savedsearches.jl")
include("search.jl")
include("spam.jl")
include("streaming.jl")
include("suggestedusers.jl")
include("timelines.jl")
include("trends.jl")
include("tweets.jl")
include("types.jl")
Expand Down
16 changes: 0 additions & 16 deletions src/dm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,6 @@
#
#############################################################

function get_direct_messages(; options=Dict{String, String}())

r = get_oauth("https://api.twitter.com/1.1/direct_messages.json", options)

return r.status == 200 ? JSON.parse(String(r.data)) : error("Twitter API returned $(r.status) status")

end

function get_direct_messages_sent(; options=Dict{String, String}())

r = get_oauth("https://api.twitter.com/1.1/direct_messages/sent.json", options)

return r.status == 200 ? JSON.parse(String(r.data)) : error("Twitter API returned $(r.status) status")

end

function get_direct_messages_show(id::String; options=Dict{String, String}())

#Add required parameter(s) to options dict
Expand Down
8 changes: 0 additions & 8 deletions src/favorites.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@
#
#############################################################

function get_favorites_list(; options=Dict{String, String}())

r = get_oauth("https://api.twitter.com/1.1/favorites/list.json", options)

return r.status == 200 ? JSON.parse(String(r.data)) : error("Twitter API returned $(r.status) status")

end

function post_favorites_destroy(id::String; options=Dict{String, String}())

options["id"] = id
Expand Down
16 changes: 0 additions & 16 deletions src/friendsfollowers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,3 @@ function post_friendships_update(; options=Dict{String, String}())
return r.status == 200 ? JSON.parse(String(r.data)) : error("Twitter API returned $(r.status) status")

end

function get_friends_list(; options=Dict{String, String}())

r = get_oauth("https://api.twitter.com/1.1/friends/list.json", options)

return r.status == 200 ? JSON.parse(String(r.data)) : error("Twitter API returned $(r.status) status")

end

function get_followers_list(; options=Dict{String, String}())

r = get_oauth("https://api.twitter.com/1.1/followers/list.json", options)

return r.status == 200 ? JSON.parse(String(r.data)) : error("Twitter API returned $(r.status) status")

end
40 changes: 0 additions & 40 deletions src/get_no_required_args.jl

This file was deleted.

76 changes: 0 additions & 76 deletions src/lists.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,6 @@
#
#############################################################

function get_lists(; options=Dict{String, String}())

r = get_oauth("https://api.twitter.com/1.1/lists/list.json", options)

return r.status == 200 ? JSON.parse(String(r.data)) : error("Twitter API returned $(r.status) status")

end

function get_lists_statuses(; options=Dict{String, String}())

r = get_oauth("https://api.twitter.com/1.1/lists/statuses.json", options)

return r.status == 200 ? JSON.parse(String(r.data)) : error("Twitter API returned $(r.status) status")

end

function post_lists_members_destroy(; options=Dict{String, String}())

r = post_oauth("https://api.twitter.com/1.1/lists/members/destroy.json", options)
Expand All @@ -28,23 +12,6 @@ function post_lists_members_destroy(; options=Dict{String, String}())

end

function get_lists_memberships(; options=Dict{String, String}())

r = get_oauth("https://api.twitter.com/1.1/lists/memberships.json", options)

return r.status == 200 ? JSON.parse(String(r.data)) : error("Twitter API returned $(r.status) status")

end

function get_lists_subscribers(; options=Dict{String, String}())

r = get_oauth("https://api.twitter.com/1.1/lists/subscribers.json", options)

#return to_USERS(r["users"])
return r.status == 200 ? JSON.parse(String(r.data)) : error("Twitter API returned $(r.status) status")

end

function post_lists_subscribers_create(; options=Dict{String, String}())

r = post_oauth("https://api.twitter.com/1.1/lists/subscribers/create.json", options)
Expand All @@ -69,24 +36,6 @@ function post_lists_members_createall(; options=Dict{String, String}())

end

function get_lists_members_show(; options=Dict{String, String}())

r = get_oauth("https://api.twitter.com/1.1/lists/members/show.json", options)

#return to_USERS(r)
return r.status == 200 ? JSON.parse(String(r.data)) : error("Twitter API returned $(r.status) status")

end

function get_lists_members(; options=Dict{String, String}())

r = get_oauth("https://api.twitter.com/1.1/lists/members.json", options)

#return to_USERS(r["users"])
return r.status == 200 ? JSON.parse(String(r.data)) : error("Twitter API returned $(r.status) status")

end

function post_lists_members_create(; options=Dict{String, String}())

r = post_oauth("https://api.twitter.com/1.1/lists/members/create.json", options)
Expand Down Expand Up @@ -121,35 +70,10 @@ function post_lists_create(name::String; options=Dict{String, String}())

end

function get_lists_show(; options=Dict{String, String}())

r = get_oauth("https://api.twitter.com/1.1/lists/show.json", options)

return r.status == 200 ? JSON.parse(String(r.data)) : error("Twitter API returned $(r.status) status")

end

function get_lists_subscriptions(; options=Dict{String, String}())

r = get_oauth("https://api.twitter.com/1.1/lists/subscriptions.json", options)

return r.status == 200 ? JSON.parse(String(r.data)) : error("Twitter API returned $(r.status) status")

end

function post_lists_members_destroyall(; options=Dict{String, String}())

r = post_oauth("https://api.twitter.com/1.1/lists/members/destroy_all.json", options)

return r.status == 200 ? JSON.parse(String(r.data)) : error("Twitter API returned $(r.status) status")

end

function get_lists_ownerships(; options=Dict{String, String}())

r = get_oauth("https://api.twitter.com/1.1/lists/ownerships.json", options)

#return to_LISTS(r["lists"])
return r.status == 200 ? JSON.parse(String(r.data)) : error("Twitter API returned $(r.status) status")

end
64 changes: 64 additions & 0 deletions src/no_required_args.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#########################################################################
#
# Endpoints with no required arguments
#
#########################################################################

endpoint_tuple = [
(:get_oauth, :get_help_configuration, "help/configuration.json"),
(:get_oauth, :get_help_languages, "help/languages.json"),
(:get_oauth, :get_help_privacy, "help/privacy.json"),
(:get_oauth, :get_help_tos, "help/tos.json"),
(:get_oauth, :get_application_rate_limit_status, "application/rate_limit_status.json"),
(:get_oauth, :get_profile_banner, "users/profile_banner.json"),
(:get_oauth, :get_blocks_ids, "blocks/ids.json"),
(:get_oauth, :get_account_settings, "account/settings.json"),
(:get_oauth, :get_oembed, "statuses/oembed.json"),
(:get_oauth, :get_trends_available, "trends/available.json"),
(:get_oauth, :get_user_suggestions, "users/suggestions.json"),
(:get_oauth, :get_saved_searches_list, "saved_searches/list.json"),
(:get_oauth, :get_lists_subscribers_show, "lists/subscribers/show.json"),
(:get_oauth, :get_friendships_no_retweets, "friendships/no_retweets/ids.json"),
(:get_oauth, :get_friends_ids, "friends/ids.json"),
(:get_oauth, :get_followers_ids, "followers/ids.json"),
(:get_oauth, :get_friendships_lookup, "friendships/lookup.json"),
(:get_oauth, :get_friendships_incoming, "friendships/incoming.json"),
(:get_oauth, :get_friendships_outgoing, "friendships/outgoing.json"),
(:get_oauth, :get_friendships_show, "friendships/show.json"),
(:get_oauth, :get_direct_messages, "direct_messages.json"),
(:get_oauth, :get_direct_messages_sent, "direct_messages/sent.json"),
(:get_oauth, :get_favorites_list, "favorites/list.json"),
(:get_oauth, :get_friends_list, "friends/list.json"),
(:get_oauth, :get_followers_list, "followers/list.json"),
(:get_oauth, :get_lists, "lists/list.json"),
(:get_oauth, :get_lists_statuses, "lists/statuses.json"),
(:get_oauth, :get_lists_memberships, "lists/memberships.json"),
(:get_oauth, :get_lists_subscribers, "lists/subscribers.json"),
(:get_oauth, :get_lists_members_show, "members/show.json"),
(:get_oauth, :get_lists_members, "lists/members.json"),
(:get_oauth, :get_lists_show, "lists/show.json"),
(:get_oauth, :get_lists_subscriptions, "lists/subscriptions.json"),
(:get_oauth, :get_lists_ownerships, "lists/ownerships.json"),
(:get_oauth, :get_mentions_timeline, "statuses/mentions_timeline.json"),
(:get_oauth, :get_user_timeline, "statuses/user_timeline.json"),
(:get_oauth, :get_home_timeline, "statuses/home_timeline.json"),
(:get_oauth, :get_retweets_of_me, "statuses/retweets_of_me.json"),
(:get_oauth, :get_verify_credentials, "account/verify_credentials.json"),
(:get_oauth, :get_blocks_list, "blocks/list.json"),
(:get_oauth, :get_users_lookup, "users/lookup.json"),
(:get_oauth, :get_users_show, "users/show.json"),
(:get_oauth, :get_users_contributees, "users/contributees.json"),
(:get_oauth, :get_users_contributors, "users/contributors.json")
]

for (verb, func, endp) in endpoint_tuple
@eval begin
function ($func)(; options=Dict{String, String}())

r = ($verb)($"https://api.twitter.com/1.1/$endp", options)

return r.status == 200 ? JSON.parse(String(r.data)) : error("Twitter API returned $(r.status) status")

end
end
end
31 changes: 0 additions & 31 deletions src/savedsearches.jl

This file was deleted.

Loading

0 comments on commit 3600d4f

Please sign in to comment.