opic 0.0.1 → 0.0.2
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.
- data/README.md +9 -1
- data/lib/opic.rb +12 -18
- data/opic.gemspec +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -18,7 +18,15 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
|
22
|
+
# Getting an existing opic
|
23
|
+
Opic.get 'decot.7', width: 200 # "https://opic.osu.edu/decot.7?width=200&aspect=s"
|
24
|
+
|
25
|
+
# Uploading a new opic
|
26
|
+
Opic.api_key = "xxxx"
|
27
|
+
file = File.new(some_kind_of_path)
|
28
|
+
Opic.post('decot.7', file) # true
|
29
|
+
|
22
30
|
|
23
31
|
## Contributing
|
24
32
|
|
data/lib/opic.rb
CHANGED
@@ -1,25 +1,15 @@
|
|
1
1
|
require 'singleton'
|
2
2
|
require "rest_client"
|
3
|
+
require 'pry'
|
3
4
|
|
4
5
|
class Opic
|
5
6
|
include Singleton
|
7
|
+
@endpoint = "https://opic.osu.edu/"
|
8
|
+
singleton_class.class_eval do
|
9
|
+
attr_accessor :api_key, :endpoint, :error
|
10
|
+
end
|
6
11
|
|
7
12
|
class << self
|
8
|
-
def api_key
|
9
|
-
@api_key ||= nil
|
10
|
-
end
|
11
|
-
|
12
|
-
def api_key=(api_key)
|
13
|
-
@api_key = api_key
|
14
|
-
end
|
15
|
-
|
16
|
-
def endpoint
|
17
|
-
@endpoint ||= "https://opic.osu.edu/"
|
18
|
-
end
|
19
|
-
|
20
|
-
def endpoint=(endpoint)
|
21
|
-
@endpoint = endpoint
|
22
|
-
end
|
23
13
|
|
24
14
|
def get(name_n, options = {})
|
25
15
|
defaults = { width: 100, aspect: 's' }
|
@@ -30,16 +20,20 @@ class Opic
|
|
30
20
|
# TODO: I don't like the fact that we're using rest_client here...I would
|
31
21
|
# rather use net/http because it's part of the ruby stdlib
|
32
22
|
|
33
|
-
def post(name_n,
|
23
|
+
def post(name_n, file)
|
34
24
|
begin
|
35
25
|
raise "API Key not set!" if @api_key.nil?
|
36
26
|
|
27
|
+
# If we were passed only a path then make a File
|
28
|
+
file = File.new(file) unless file.is_a? File
|
29
|
+
|
37
30
|
headers = { "X-API-Key" => @api_key }
|
38
|
-
data = { avatar:
|
31
|
+
data = { avatar: file, name_n: name_n }
|
39
32
|
|
40
|
-
r = RestClient.post("#{@endpoint}
|
33
|
+
r = RestClient.post("#{@endpoint}api/avatars", data, headers)
|
41
34
|
return false unless r.code == 201
|
42
35
|
rescue => e
|
36
|
+
@error = e
|
43
37
|
return false
|
44
38
|
end
|
45
39
|
return true
|
data/opic.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "opic"
|
7
|
-
spec.version = "0.0.
|
7
|
+
spec.version = "0.0.2"
|
8
8
|
spec.authors = ["Kyle Decot"]
|
9
9
|
spec.email = ["decot.7@osu.edu"]
|
10
10
|
spec.description = %q{Rubygem for interacting w/ the Opic API}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -123,7 +123,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
123
|
version: '0'
|
124
124
|
segments:
|
125
125
|
- 0
|
126
|
-
hash: -
|
126
|
+
hash: -21967378471575377
|
127
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
128
|
none: false
|
129
129
|
requirements:
|
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
132
|
version: '0'
|
133
133
|
segments:
|
134
134
|
- 0
|
135
|
-
hash: -
|
135
|
+
hash: -21967378471575377
|
136
136
|
requirements: []
|
137
137
|
rubyforge_project:
|
138
138
|
rubygems_version: 1.8.25
|