Skip to content

Commit

Permalink
Accept Pinboard API token instead of username/password.
Browse files Browse the repository at this point in the history
  • Loading branch information
benubois committed May 11, 2014
1 parent 60c2b0e commit 7e585ff
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/_site.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4207,11 +4207,11 @@ select {
line-height: 20px;
}

.alert-info,
.alert-success {
background-color: $selected;
}

.alert-info,
.alert-danger,
.alert-error {
background-color: #d61f33;
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/supported_sharing_services_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def xauth_request(service_id)
redirect_to sharing_services_url, alert: "Unknown #{service_info[:label]} error."
end
rescue OAuth::Unauthorized
redirect_to sharing_services_url, alert: "Invalid #{service_info[:label]} username or password."
redirect_to sharing_services_url, alert: "Invalid #{service_info[:label]} login."
rescue
redirect_to sharing_services_url, alert: "Unknown #{service_info[:label]} error."
end
Expand Down
5 changes: 2 additions & 3 deletions app/supported_sharing_services/pinboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ def initialize(klass = nil)
end

def request_token(username, password)
response = self.class.get('/user/api_token', basic_auth: {username: username, password: password}, query: {format: 'json'})
response = self.class.get('/user/api_token', query: {auth_token: password, format: 'json'})
if response.code == 401
raise OAuth::Unauthorized
else
response = JSON.load(response.body)
OpenStruct.new(token: "#{username}:#{response['result']}", secret: 'n/a')
OpenStruct.new(token: password, secret: 'n/a')
end
end

Expand Down
11 changes: 11 additions & 0 deletions app/views/supported_sharing_services/_pinboard_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class="service-options hide">
<%= form_for(record) do |f| %>
<%= f.hidden_field :service_id, value: sharing_service[:service_id] %>
<%= f.hidden_field :operation, value: 'authorize' %>
<%= password_field_tag 'password', '', placeholder: 'API Token', class: 'no-margin' %>

<%= link_to 'Cancel', '#', class: 'action-button button-danger button-link cancel-button', data: {behavior: "hide_service_options"} %>
<%= submit_tag "Login", class: 'action-button button button-primary' %>
<% end %>
<small>You can find your API token on your <a href="https://pinboard.in/settings/password" target="_blank">Pinboard Password page</a>.</small>
</div>
13 changes: 12 additions & 1 deletion app/views/supported_sharing_services/_service_pinboard.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
<%= render partial: "supported_sharing_services/type_xauth", locals: {sharing_service: sharing_service, status: status, record: record} %></li>
<% if status == :active %>
<%= render partial: "supported_sharing_services/delete_supported_service", locals: {sharing_service: sharing_service} %>
<% elsif status == :issue %>
<p class="service-title <%= "icon-share-#{sharing_service.service_id}" %>"><%= sharing_service.label %></p>
<small class="show-service-options">Feedbin can no longer access <%= sharing_service.label %>, <a href="#" data-behavior="show_service_options">reactivate</a>?</small>
<%= link_to 'Deactivate', supported_sharing_service_path(sharing_service), class: 'list-action danger show-service-options', method: :delete %>
<%= render partial: "supported_sharing_services/pinboard_form", locals: {sharing_service: sharing_service, record: record} %>
<% else %>
<p class="service-title <%= "icon-share-#{sharing_service[:service_id]}" %>"><%= sharing_service[:label] %></p>
<%= link_to 'Activate', '#', class: 'list-action show-service-options', data: {behavior: "show_service_options"} %>
<%= render partial: "supported_sharing_services/pinboard_form", locals: {sharing_service: sharing_service, record: record} %>
<% end %>

0 comments on commit 7e585ff

Please sign in to comment.