nano_twitter 0.7
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.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +42 -0
- data/README.md +39 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/nano_twitter.rb +60 -0
- data/lib/nano_twitter/version.rb +3 -0
- data/nano_twitter.gemspec +30 -0
- data/test.rb +94 -0
- metadata +152 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e33c4516d8e8ac6470b166147a8c24e22cb900de4fe0f005cc7c595156766bf8
|
4
|
+
data.tar.gz: e6d472131d0b3fa07b52a04b8034890357f4d4666643fc86398203fd3ed9718c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4bd7efcad5e0c4868186c581f97d745c86e9479f00471a71e9055057009ecb81f2579e4ae80a8b973ed27c6d027e95b0677a0ea16c1ab610e3003a6de4dc6301
|
7
|
+
data.tar.gz: 6a8099175163a91a9d2a1861f8f8376c06533778752de1bd291699e34cc123a4c4137365362c159a14075bd20828c66461078cb21a1215646de255f376e94038
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
nano_twitter (0.7)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
byebug (11.0.1)
|
10
|
+
docile (1.3.1)
|
11
|
+
httparty (0.16.4)
|
12
|
+
mime-types (~> 3.0)
|
13
|
+
multi_xml (>= 0.5.2)
|
14
|
+
json (2.2.0)
|
15
|
+
mime-types (3.2.2)
|
16
|
+
mime-types-data (~> 3.2015)
|
17
|
+
mime-types-data (3.2018.0812)
|
18
|
+
minitest (5.11.3)
|
19
|
+
multi_xml (0.6.0)
|
20
|
+
rake (10.5.0)
|
21
|
+
rb-readline (0.5.5)
|
22
|
+
simplecov (0.16.1)
|
23
|
+
docile (~> 1.1)
|
24
|
+
json (>= 1.8, < 3)
|
25
|
+
simplecov-html (~> 0.10.0)
|
26
|
+
simplecov-html (0.10.2)
|
27
|
+
|
28
|
+
PLATFORMS
|
29
|
+
ruby
|
30
|
+
|
31
|
+
DEPENDENCIES
|
32
|
+
bundler (~> 2.0)
|
33
|
+
byebug
|
34
|
+
httparty
|
35
|
+
minitest
|
36
|
+
nano_twitter!
|
37
|
+
rake (~> 10.0)
|
38
|
+
rb-readline
|
39
|
+
simplecov
|
40
|
+
|
41
|
+
BUNDLED WITH
|
42
|
+
2.0.1
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# NanoTwitter
|
2
|
+
|
3
|
+
[](https://app.codeship.com/projects/333927)
|
4
|
+
[](https://codeclimate.com/github/cosi105/nano_twitter/maintainability)
|
5
|
+
[](https://codeclimate.com/github/cosi105/nano_twitter/test_coverage)
|
6
|
+
|
7
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/nano_twitter`. To experiment with that code, run `bin/console` for an interactive prompt.
|
8
|
+
|
9
|
+
TODO: Delete this and the text above, and describe your gem
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'nano_twitter'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install nano_twitter
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
TODO: Write usage instructions here
|
30
|
+
|
31
|
+
## Development
|
32
|
+
|
33
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
34
|
+
|
35
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nano_twitter.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "nano_twitter"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/nano_twitter.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require "nano_twitter/version"
|
2
|
+
require 'httparty'
|
3
|
+
require 'erb'
|
4
|
+
|
5
|
+
module NanoTwitter
|
6
|
+
class Error < StandardError; end
|
7
|
+
|
8
|
+
class Client
|
9
|
+
attr_reader :name, :handle, :password, :api_path
|
10
|
+
|
11
|
+
def initialize(handle, password, api_root)
|
12
|
+
@handle = handle
|
13
|
+
@password = password
|
14
|
+
@api_path = "#{api_root}/api/#{NanoTwitter::VERSION}"
|
15
|
+
end
|
16
|
+
|
17
|
+
# Log into nanoTwitter
|
18
|
+
def login
|
19
|
+
HTTParty.post("#{@api_path}/login/#{@handle}/#{@password}")
|
20
|
+
end
|
21
|
+
|
22
|
+
# Register/create account
|
23
|
+
def register(name)
|
24
|
+
encoded_url = url_encode "#{name}/#{@handle}/#{@password}"
|
25
|
+
HTTParty.post("#{@api_path}/signup/#{encoded_url}")
|
26
|
+
end
|
27
|
+
|
28
|
+
def url_encode(url)
|
29
|
+
token_arr = url.split '/'
|
30
|
+
encoded_arr = token_arr.map { |str| ERB::Util.url_encode str }
|
31
|
+
encoded_arr.join '/'
|
32
|
+
end
|
33
|
+
|
34
|
+
# Post a new Tweet
|
35
|
+
def tweet(tweet_body)
|
36
|
+
encoded_url = url_encode "#{@handle}/#{@password}/#{tweet_body}"
|
37
|
+
HTTParty.post("#{@api_path}/tweets/new/#{encoded_url}")
|
38
|
+
end
|
39
|
+
|
40
|
+
# Get list of Tweets in your timeline
|
41
|
+
def get_timeline
|
42
|
+
HTTParty.post("#{@api_path}/tweets/#{@handle}/#{@password}")
|
43
|
+
end
|
44
|
+
|
45
|
+
# Get list of users following you (creepy)
|
46
|
+
def get_followers
|
47
|
+
HTTParty.post("#{@api_path}/users/followers/#{@handle}/#{@password}")
|
48
|
+
end
|
49
|
+
|
50
|
+
# Get list of users you follow
|
51
|
+
def get_followees
|
52
|
+
HTTParty.post("#{@api_path}/users/followees/#{@handle}/#{@password}")
|
53
|
+
end
|
54
|
+
|
55
|
+
# Follow a new user
|
56
|
+
def follow(followee_handle)
|
57
|
+
HTTParty.post("#{@api_path}/users/follow/#{@handle}/#{@password}/#{followee_handle}")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "nano_twitter/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "nano_twitter"
|
8
|
+
spec.version = NanoTwitter::VERSION
|
9
|
+
spec.authors = ["Ari Carr"]
|
10
|
+
spec.email = ["acarr@brandeis.edu"]
|
11
|
+
|
12
|
+
spec.summary = "A client gem for NanoTwitter, our COSI 105B project"
|
13
|
+
|
14
|
+
# Specify which files should be added to the gem when it is released.
|
15
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
16
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
17
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "httparty"
|
26
|
+
spec.add_development_dependency "byebug"
|
27
|
+
spec.add_development_dependency "rb-readline"
|
28
|
+
spec.add_development_dependency "simplecov"
|
29
|
+
spec.add_development_dependency "minitest"
|
30
|
+
end
|
data/test.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
SimpleCov.command_name 'test:units'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'nano_twitter'
|
6
|
+
require 'httparty'
|
7
|
+
|
8
|
+
# Uncomment this to run the tests on Heroku
|
9
|
+
NT_PATH = 'https://nano-twitter.herokuapp.com'
|
10
|
+
|
11
|
+
# Uncomment this if you're running everything locally
|
12
|
+
# NT_PATH = 'http://localhost:4567'
|
13
|
+
|
14
|
+
def assert_success(req)
|
15
|
+
req.success?.must_equal true
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'NanoTwitter Gem' do
|
19
|
+
|
20
|
+
before do
|
21
|
+
handle = '@gem_tester'
|
22
|
+
password = '@gem_tester'
|
23
|
+
@name = 'Gem McTester'
|
24
|
+
@client = NanoTwitter::Client.new(handle, password, NT_PATH)
|
25
|
+
@client.register(@name)
|
26
|
+
end
|
27
|
+
|
28
|
+
Minitest.after_run { HTTParty.post("#{NT_PATH}/test/reset/all") }
|
29
|
+
|
30
|
+
describe 'NanoTwitter Gem After Registration' do
|
31
|
+
it 'can log in as a user' do
|
32
|
+
assert_success @client.login
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'can post a tweet' do
|
36
|
+
assert_success @client.tweet("Look Ma, I'm tweeting!")
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'Following' do
|
40
|
+
|
41
|
+
before do
|
42
|
+
@second_user = NanoTwitter::Client.new('@gem_test_followee', '@gem_test_followee', NT_PATH)
|
43
|
+
@second_user.register 'Test Followee'
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'can follow a user' do
|
47
|
+
follow_resp = @client.follow('@gem_test_followee')
|
48
|
+
json_resp = JSON.parse(follow_resp.parsed_response)
|
49
|
+
json_resp['name'].must_equal '@gem_test_followee'
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'can get followers' do
|
53
|
+
@client.follow('@gem_test_followee')
|
54
|
+
sleep(0.01)
|
55
|
+
|
56
|
+
get_resp = @second_user.get_followers
|
57
|
+
json_resp = JSON.parse(get_resp.parsed_response)
|
58
|
+
json_resp.size.must_equal 1
|
59
|
+
|
60
|
+
first_follower = json_resp.first
|
61
|
+
first_follower['name'].must_equal 'Gem McTester'
|
62
|
+
first_follower['handle'].must_equal '@gem_tester'
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'can get followees' do
|
66
|
+
@client.follow('@gem_test_followee')
|
67
|
+
sleep(0.01)
|
68
|
+
|
69
|
+
get_resp = @client.get_followees
|
70
|
+
json_resp = JSON.parse(get_resp.parsed_response)
|
71
|
+
json_resp.size.must_equal 1
|
72
|
+
|
73
|
+
first_followee = json_resp.first
|
74
|
+
first_followee['name'].must_equal 'Test Followee'
|
75
|
+
first_followee['handle'].must_equal '@gem_test_followee'
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'can get timeline' do
|
79
|
+
@client.follow('@gem_test_followee')
|
80
|
+
sleep(0.01)
|
81
|
+
tweet_text = 'Hey followers!'
|
82
|
+
@second_user.tweet tweet_text
|
83
|
+
sleep(0.01)
|
84
|
+
|
85
|
+
timeline_resp = @client.get_timeline
|
86
|
+
json_resp = JSON.parse timeline_resp.parsed_response
|
87
|
+
|
88
|
+
json_resp.size.must_equal 1
|
89
|
+
|
90
|
+
json_resp.first['body'].must_equal tweet_text
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
metadata
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nano_twitter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.7'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ari Carr
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-04-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: httparty
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
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: rb-readline
|
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
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: minitest
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- acarr@brandeis.edu
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- Gemfile
|
120
|
+
- Gemfile.lock
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- bin/console
|
124
|
+
- bin/setup
|
125
|
+
- lib/nano_twitter.rb
|
126
|
+
- lib/nano_twitter/version.rb
|
127
|
+
- nano_twitter.gemspec
|
128
|
+
- test.rb
|
129
|
+
homepage:
|
130
|
+
licenses: []
|
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.7.6
|
149
|
+
signing_key:
|
150
|
+
specification_version: 4
|
151
|
+
summary: A client gem for NanoTwitter, our COSI 105B project
|
152
|
+
test_files: []
|